Ruby send vs __send__

后端 未结 5 1499
长情又很酷
长情又很酷 2020-12-12 13:36

I understand the concept of some_instance.send but I\'m trying to figure out why you can call this both ways. The Ruby Koans imply that there is some reason bey

5条回答
  •  悲&欢浪女
    2020-12-12 14:13

    __send__ exists so it can't be over-written by accident.

    As for why send exists: I can't speak for anyone else, but object.send(:method_name, *parameters) looks nicer than object.__send__(:method_name, *parameters), so I use send unless I need to use __send__.

提交回复
热议问题