Created
April 2, 2012 16:22
-
-
Save everm1nd/2284750 to your computer and use it in GitHub Desktop.
Ruby: method_missing metaprogramming
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
# 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