-
-
Save wycats/363843 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
module EasySelectFields | |
def easy_select_fields(a,options) | |
type_method_name = "#{a}_types".to_sym | |
array = options.each_with_index.map {|o,i| [o, i] } | |
class_eval "def self.#{a}_types() #{array.inspect} end" | |
end | |
end | |
class Person | |
extend EasySelectFields | |
easy_select_fields "status", ["Interested", "Not Interested", "Available"] | |
end |
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
require "active_support/core_ext/kernel/singleton_class" | |
module EasySelectFields | |
def easy_select_fields(a,options) | |
type_method_name = "#{a}_types".to_sym | |
array = options.each_with_index.map {|o,i| [o, i] } | |
singleton_class.class_eval do | |
define_method("#{a}_types") { array } | |
end | |
end | |
end | |
class Person | |
extend EasySelectFields | |
easy_select_fields "status", ["Interested", "Not Interested", "Available"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment