これはわかりません。
method_missing
は、オーバーヘッドが一度しか発生しないように、呼び出されたメソッドを動的にクラスに追加するのが最も効率的です。それ以降は、他の方法と同様にメソッドを呼び出します。
のような:実行したときにこれを吐く
class Foo
def method_missing(name, str)
# log something out when we call method_missing so we know it only happens once
puts "Defining method named: #{name}"
# Define the new instance method
self.class.class_eval <<-CODE
def #{name}(arg1)
puts 'you passed in: ' + arg1.to_s
end
CODE
# Run the instance method we just created to return the value on this first run
send name, str
end
end
# See if it works
f = Foo.new
f.echo_string 'wtf'
f.echo_string 'hello'
f.echo_string 'yay!'
:
Defining method named: echo_string
you passed in: wtf
you passed in: hello
you passed in: yay!
はそう考えてはいけない - スーパークラスの実装があるかどうメソッドが欠落していません。 –