Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Created December 18, 2008 18:32
Show Gist options
  • Save redsquirrel/37585 to your computer and use it in GitHub Desktop.
Save redsquirrel/37585 to your computer and use it in GitHub Desktop.
class Module
def bool_accessor(attribute)
attr_accessor attribute
define_method(attribute.to_s + "?") do
!!send(attribute)
end
end
end
class Bar
bool_accessor :has_foo
end
bar = Bar.new
puts bar.has_foo?
bar.has_foo = true
puts bar.has_foo?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment