Skip to content

Instantly share code, notes, and snippets.

@anr
Created May 20, 2010 00:24
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 anr/407035 to your computer and use it in GitHub Desktop.
Save anr/407035 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
module StatusField
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def status_field(*args)
# Problem: create a class method that returns an array
# containing all defined status.
# What I'd like to do:
# instance_eval { define_method(:status_all) { args } }
# My silly solution:
instance_eval %{
def status_all
"#{args.join(' ')}".split
end
}
end
end
end
class Foo
include StatusField
status_field :off, :on
end
p Foo.status_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment