Created
May 20, 2010 00:24
-
-
Save anr/407035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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