【发布时间】:2016-12-06 21:28:54
【问题描述】:
所以我尝试在Ruby中编写method_missing,method_missing有三个参数,如图所示
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" } 的问题总是返回 " Sample One No arguments were given or block"。 很明显 block_given 总是返回 false ,但是为什么呢?
【问题讨论】:
-
无法重现:
Foo.new.anything {} # there was ?code given
标签: ruby-on-rails ruby