Hi All
I have a method name stored in a variable. How do I now invoke the
method ?
my_var = ‘some_method’
my_obj = Some_Obj.new
my_obj.my_var()
doesn’t work
Any suggestion
thnx a lot
LuCa
Hi All
I have a method name stored in a variable. How do I now invoke the
method ?
my_var = ‘some_method’
my_obj = Some_Obj.new
my_obj.my_var()
doesn’t work
Any suggestion
thnx a lot
LuCa
Alle Sunday 27 January 2008, Luca S. ha scritto:
doesn’t work
Any suggestion
thnx a lot
LuCa
my_object.send( my_var)
Stefano
thats it, thnx!!
An other question, is it possible to assign a value to an attribute this
way
For example, this doesn’t work
my_object.send(my_var) = 2000
thnx in advance
LuCa
Stefano C. wrote:
Alle Sunday 27 January 2008, Luca S. ha scritto:
doesn’t work
Any suggestion
thnx a lot
LuCamy_object.send( my_var)
Stefano
Alle Sunday 03 February 2008, Luca S. ha scritto:
Stefano C. wrote:
Stefano
Yes, you can. You must understand that, when you do:
my_object.my_var= 2000
you’re actually calling the my_var= method of my_object with argument
2000.
Therefore, to do this with send, you need to do:
my_object.send(:my_var=, 2000)
Stefano
that makes sense, now I understand what send() is actually doing!
thnx!!!
LuCa
Luca S. wrote:
For example, this doesn’t work
my_object.send(my_var) = 2000
If you use attr_writer :foo, it creates the method foo= which takes one
argument. So you’d call it like this:
send(:foo=, 2000)
or
my_var = “foo”
send("#{my_var}=", 2000)
HTH,
Sebastian
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