所以我想写Ruby中的method_missing,该method_missing方法有三个参数,如图block_given?始终返回false
def method_missing(mId,*args,&block)
if (args.empty? && !block_given?)
puts " Sample One No arguments were given nor block"
elsif (!args.entries.empty?)
puts " there was arguments given"
elsif (block_given?)
puts "there was ?code given"
end
end
问题致电instance.anything {“块”}总是返回“样品中的一个没有论据给定也不阻止“。 很明显,block_given总是返回false,但是为什么?
无法重现:'Foo.new.anything {}#有代码given' –