所以我想寫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' –