Created
April 5, 2012 11:18
-
-
Save mlangenberg/2310034 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Definition | |
def element(name) | |
attr_accessor name | |
define_method name.to_s+'?' do | |
!!name # bound to local variable, not calling method. but !!send(name) is ugly | |
end | |
end | |
end | |
class Kitty | |
extend Definition | |
element 'purring' | |
end | |
k = Kitty.new | |
k.purring = false | |
puts k.purring? #=> true ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment