lib/hobo_fields/enum_string.rb in hobofields-0.8.3 vs lib/hobo_fields/enum_string.rb in hobofields-0.8.4
- old
+ new
@@ -25,10 +25,10 @@
def for(*values)
values = values.*.to_s
c = Class.new(EnumString) do
values.each do |v|
- const_name = v.upcase
+ const_name = v.upcase.gsub(/[^a-z0-9_]/i, '_').gsub(/_+/, '_')
const_set(const_name, self.new(v)) unless const_defined?(const_name)
method_name = "is_#{v.underscore}?"
define_method(method_name) { self == v } unless self.respond_to?(method_name)
end