Skip to content

Instantly share code, notes, and snippets.

@everm1nd
Created April 2, 2012 16:22
Show Gist options
  • Save everm1nd/2284750 to your computer and use it in GitHub Desktop.
Save everm1nd/2284750 to your computer and use it in GitHub Desktop.
Ruby: method_missing metaprogramming
# Let say we're defining method for #*_with_id here
def method_missing(name, *args)
super if name !~ /_with_id$/
define_method "#{name}_with_id" do
instance_variable_get(:id) + "-" + instance_variable_get(:name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment