Skip to content

Instantly share code, notes, and snippets.

@mlangenberg
Created April 5, 2012 11:18
Show Gist options
  • Save mlangenberg/2310034 to your computer and use it in GitHub Desktop.
Save mlangenberg/2310034 to your computer and use it in GitHub Desktop.
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