Skip to content

Instantly share code, notes, and snippets.

@alloy
Created February 16, 2009 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloy/65201 to your computer and use it in GitHub Desktop.
Save alloy/65201 to your computer and use it in GitHub Desktop.
class Foo
def self.string_query_accessor(attr, *true_values)
true_values.each do |true_value|
class_eval %{
def #{true_value}?
send(:#{attr}) == '#{true_value}'
end
}, __FILE__, __LINE__
end
end
attr_accessor :foo
string_query_accessor :foo, 'bar', 'baz'
end
f = Foo.new
f.foo = 'bar'
p f.bar?, f.baz?
f.foo = 'baz'
p f.bar?, f.baz?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment