Hi
How can I pass parameters to the method, test_method And also would
like to know what is __ in send ?
Thanks
Hi
How can I pass parameters to the method, test_method And also would
like to know what is __ in send ?
Thanks
Sijo Kg wrote:
Hi
How can I pass parameters to the method
foo.__send__(:test_method, arg1, arg2)
Or if the args are in an array already:
foo.__send__(:test_method, *args)
And also would
like to know what is __ in send ?
It’s two underscores
Here’s what “ri send” says:
Invokes the method identified by _symbol_, passing it any arguments
specified. You can use +__send__+ if the name +send+ clashes with
an existing method in _obj_.
class Klass
def hello(*args)
"Hello " + args.join(' ')
end
end
k = Klass.new
k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
Hi
Thanks for your reply
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs