G
Giulio Piancastelli
I'm wondering... does Object#send start from the Object class to search
for the method to execute? I'm leading to this conclusion because of a
little class I'm working on where I'm using send to execute methods,
and one of the methods I'm trying to execute is called 'select' and
takes a number as its parameter. Unfortunately, this name happens to
clash with Kernel.select, which instead takes an array as a parameter.
Thus, an exception is thrown, leading to the "wrong argument type
Fixnum (expected Array)" message.
I suppose it's impossible to make Object#send search from where the
method has been called instead of Object itself... but, is there a way
to have the B#select method called instead of the select method in
Kernel? I'd like not to change names nor the design of A and B, if
that's possible.
On the other hand, the following sketch just works:
class A
def make_it_so arg0
send(arg0.text, 1)
end
end
class B < A
def select index
puts index
end
end
b = B.new
b.make_it_so(param) # where param.text returns 'select'
so, it's probably that I don't understand what's really happening...
Can anyone help enlight me on the topic?
Best Regards,
Giulio Piancastelli.
for the method to execute? I'm leading to this conclusion because of a
little class I'm working on where I'm using send to execute methods,
and one of the methods I'm trying to execute is called 'select' and
takes a number as its parameter. Unfortunately, this name happens to
clash with Kernel.select, which instead takes an array as a parameter.
Thus, an exception is thrown, leading to the "wrong argument type
Fixnum (expected Array)" message.
I suppose it's impossible to make Object#send search from where the
method has been called instead of Object itself... but, is there a way
to have the B#select method called instead of the select method in
Kernel? I'd like not to change names nor the design of A and B, if
that's possible.
On the other hand, the following sketch just works:
class A
def make_it_so arg0
send(arg0.text, 1)
end
end
class B < A
def select index
puts index
end
end
b = B.new
b.make_it_so(param) # where param.text returns 'select'
so, it's probably that I don't understand what's really happening...
Can anyone help enlight me on the topic?
Best Regards,
Giulio Piancastelli.