Skip to content

Instantly share code, notes, and snippets.

@fuse
Created May 31, 2011 11:12
Show Gist options
  • Save fuse/1000324 to your computer and use it in GitHub Desktop.
Save fuse/1000324 to your computer and use it in GitHub Desktop.
class Cat
STATES = ["hungry", "sated"].freeze
attr_accessor :state
STATES.each do |state|
define_method "#{state}?" do
state == self.state
end
end
end
garfield.state = "hungry"
p garfield.hungry?
# true
p garfield.sated?
# false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment