method_missing gotchas in Ruby

前端 未结 6 770
天命终不由人
天命终不由人 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:47

    Building on Pistos's point: method_missing is at least an order of magnitude slower than regular method calling on all the Ruby implementations I've tried. He is right to anticipate when possible to avoid calls to method_missing.

    If you're feeling adventurous, check out Ruby's little-known Delegator class.

提交回复
热议问题