Skip to content

Commit

Permalink
No more hijacking enum initialize method
Browse files Browse the repository at this point in the history
  • Loading branch information
beerlington committed Nov 12, 2011
1 parent 8d50763 commit a5162eb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/classy_enum/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@ def enum_classes(*enums)
@index = index + 1
@option = option

attr_accessor :owner, :serialize_as_json
attr_accessor :owner, :serialize_as_json, :to_s, :index

# Use ActiveModel::AttributeMethods to define attribute? methods
attribute_method_suffix '?'
define_attribute_methods enums

def initialize
@to_s = self.class.instance_variable_get('@option').to_s
@index = self.class.instance_variable_get('@index')
end

end

klass_name = "#{self}#{option.to_s.camelize}"
Expand All @@ -60,6 +55,9 @@ def build(value, options={})
object = Object.const_get("#{self}#{value.to_s.camelize}").new
object.owner = options[:owner]
object.serialize_as_json = options[:serialize_as_json]
object.to_s = object.class.instance_variable_get('@option').to_s
object.index = object.class.instance_variable_get('@index')

object
end

Expand Down

0 comments on commit a5162eb

Please sign in to comment.