Last active
August 29, 2015 14:00
-
-
Save jay16/11167872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@solife tools]# ruby method_missing.rb | |
method missing stack called.. | |
define_method: title | |
"title" | |
"title" | |
no mater what you do, i say: hello | |
[root@solife tools]# cat method_missing.rb | |
class A | |
def method_missing(method_id, *args) | |
puts "method missing stack called.." | |
if method_id.to_s =~ /^find_by_(.*?)$/ | |
name = $1 | |
puts "define_method: " + name | |
self.class.send(:define_method, method_id) do | |
name | |
end | |
send(method_id, *args) | |
else | |
super | |
end | |
end | |
end | |
class Object | |
def method_missing(method_id, *args) | |
puts "no mater what you do, i say: " + method_id.to_s | |
end | |
end | |
obj = A.new | |
p obj.find_by_title | |
p obj.find_by_title | |
1.hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment