What does send() do in Ruby?

后端 未结 6 1008
野性不改
野性不改 2020-11-28 01:49

Can someone please tell me what

send(\"#{Model.find...}\")

is and does?

6条回答
  •  执笔经年
    2020-11-28 02:30

    send is a ruby (without rails) method allowing to invoke another method by name.

    From documentation

       class Klass
         def hello(*args)
           "Hello " + args.join(' ')
         end
       end
       k = Klass.new
       k.send :hello, "gentle", "readers"   #=> "Hello gentle readers"
    

    http://corelib.rubyonrails.org/classes/Object.html#M001077

提交回复
热议问题