Skip to content

Instantly share code, notes, and snippets.

@r00k
Created February 11, 2011 20:45
Show Gist options
  • Save r00k/822994 to your computer and use it in GitHub Desktop.
Save r00k/822994 to your computer and use it in GitHub Desktop.
def foo?
self.status == 'foo'
end
def bar?
self.status == 'bar'
end
# duplication! accomplish the same thing with define_method:
[:foo, :bar].each do |status|
define_method("#{status}?") do
self.status == status.to_s
end
end
# awwwww yeah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment