`respond_to?` vs. `respond_to_missing?`

前端 未结 2 400
轻奢々
轻奢々 2021-01-31 07:37

What is the point of defining respond_to_missing? as opposed to defining respond_to?? What goes wrong if you redefine respond_to? for some

2条回答
  •  Happy的楠姐
    2021-01-31 08:24

    It's a good practice to create respond_to_missing? if you are overriding method_missing. That way, the class will tell you the method you are calling exists, even though it's not explicitly declared.

    respond_to? should probably not be overriden :)

提交回复
热议问题