Skip to content

Instantly share code, notes, and snippets.

@kano4
Created October 13, 2011 04:21
Show Gist options
  • Save kano4/1283364 to your computer and use it in GitHub Desktop.
Save kano4/1283364 to your computer and use it in GitHub Desktop.
modify method_missing in Ruby
class String
def method_missing(method)
return "#{self}: get #{$1}!" if method.to_s =~ /^get_(.*)_method$/
"Hello, method_missing! (you call '#{method}' method)"
# super
end
end
puts "hoge".get_foo_method
puts "hoge".moge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment