Created
August 24, 2009 08:49
-
-
Save phoet/173762 to your computer and use it in GitHub Desktop.
example of i don't give a shit gem
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
alias :method_missing_i_dont_give_a_shit :method_missing | |
def method_missing(sym,*args, &block) | |
puts "sym is #{sym}" | |
method_name = sym.to_s | |
if /.+\?$/ =~ method_name | |
puts "i dont care" | |
target_method = method_name[0..-2] | |
puts "target is #{target_method}" | |
puts self.class | |
if self == nil and not /^to_.+/ =~ target_method | |
puts "current is self" | |
nil | |
else | |
puts "not self" | |
self.send(target_method, *args, &block) | |
end | |
else | |
puts "old method missing" | |
method_missing_i_dont_give_a_shit(sym, *args, &block) | |
end | |
end | |
puts nil.i?.dont?.give?.a?.shit?.class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment