P
Peña, Botp
Hi Friends,
Forgive me in adv for asking a newbie question.
1. First question: How do I get the the method passed?
Eg.
class Dog
def bark
'arf!arf!'
end
def method_missing(x)
p "method missing"
"sorry, cannot do #{x} in #{self}"
end
end
beethoven = Dog.new
p beethoven.bark
p beethoven.purr
#-------------------------
"sorry, cannot do purr in #<Dog:0x2777228>"
I'd like a method similar to method_missing(x) (wherein the methodname is
passed in x), but only access it before a method is run (maybe name it
method_called(x)).
So I can do (maybe),
...
Class Dog
...
def method_called(x)
p "You ask for #{x}"
end
end
------------------
"arf!arf!"
"You ask for purr"
"sorry, cannot do purr in #<Dog:0x2777228>"
2. 2nd question: How do I get the receiver that received the method passed?
So that:
"arf!arf!"
"You ask for purr thru beethoven"
"sorry, cannot do purr thru beethoven"
That is all ..for the moment. Sorry for the lengthy post.
thank you in advance.
kind regards -botp
Forgive me in adv for asking a newbie question.
1. First question: How do I get the the method passed?
Eg.
#-------------------------cat test1.rb
class Dog
def bark
'arf!arf!'
end
def method_missing(x)
p "method missing"
"sorry, cannot do #{x} in #{self}"
end
end
beethoven = Dog.new
p beethoven.bark
p beethoven.purr
#-------------------------
"arf!arf!"ruby -w test1.rb
"sorry, cannot do purr in #<Dog:0x2777228>"
I'd like a method similar to method_missing(x) (wherein the methodname is
passed in x), but only access it before a method is run (maybe name it
method_called(x)).
So I can do (maybe),
...
Class Dog
...
def method_called(x)
p "You ask for #{x}"
end
end
------------------
"You ask for bark"ruby -w test1.rb
"arf!arf!"
"You ask for purr"
"sorry, cannot do purr in #<Dog:0x2777228>"
2. 2nd question: How do I get the receiver that received the method passed?
So that:
"You ask for bark thru beethoven"ruby -w test1.rb
"arf!arf!"
"You ask for purr thru beethoven"
"sorry, cannot do purr thru beethoven"
That is all ..for the moment. Sorry for the lengthy post.
thank you in advance.
kind regards -botp