Skip to content

Instantly share code, notes, and snippets.

@phoet
Created August 24, 2009 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoet/173762 to your computer and use it in GitHub Desktop.
Save phoet/173762 to your computer and use it in GitHub Desktop.
example of i don't give a shit gem
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