method_missing gotchas in Ruby

前端 未结 6 772
天命终不由人
天命终不由人 2020-12-22 23:07

Are there any things to be careful about when defining the method_missing method in Ruby? I\'m wondering whether there are some not-so-obvious interactions fro

6条回答
  •  悲&欢浪女
    2020-12-22 23:36

    Another gotcha:

    method_missing behaves differently between obj.call_method and obj.send(:call_method). Essentially the former one miss all private and non-defined methods, while later one doesn't miss private methods.

    So you method_missing will never trap the call when someone calling your private method via send.

提交回复
热议问题