object_sugar 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/object_sugar.rb CHANGED
@@ -33,7 +33,8 @@ module ObjectSugar
33
33
  # Foo::MyConstants::THREE => tre
34
34
 
35
35
  def create_constants(name, *args)
36
- klass = const_set( name.to_s.camelize.to_sym, Class.new )
36
+ const = name.to_s.camelize.to_sym
37
+ klass = const_defined?(const) ? const_get(const) : const_set(name.to_s.camelize.to_sym, Class.new)
37
38
  klass.extend ObjectSugar::InstanceMethods
38
39
 
39
40
  args.flatten.each do |enum|
@@ -53,13 +54,14 @@ module ObjectSugar
53
54
  # each subsequent argument in +args+ has a value +factor+^index
54
55
 
55
56
  def create_enum(name, factor, *args)
56
- klass = const_set( name.to_s.camelize.to_sym, Class.new )
57
+ const = name.to_s.camelize.to_sym
58
+ klass = const_defined?(const) ? const_get(const) : const_set(name.to_s.camelize.to_sym, Class.new)
57
59
  klass.extend ObjectSugar::InstanceMethods
58
60
 
59
61
  args.flatten.each_with_index { |const, index|
60
62
  value = (factor == 1) ? (factor * index) : (factor.power!( index ))
61
63
 
62
- klass.const_set( const.to_s.underscore.upcase, value.to_i )
64
+ klass.const_set(const.to_s.underscore.upcase, value.to_i)
63
65
  }
64
66
 
65
67
  klass
@@ -82,9 +84,9 @@ module ObjectSugar
82
84
 
83
85
  def create_pluralized_constant(name)
84
86
  pluralized = ActiveSupport::Inflector.pluralize( name.to_s ).upcase.to_sym
85
- constants = const_get( name.to_s.camelize.to_sym ).constants
87
+ constants = const_get(name.to_s.camelize.to_sym).constants
86
88
 
87
- const_set( pluralized, constants ) unless const_defined?( pluralized )
89
+ const_set(pluralized, constants) unless const_defined?(pluralized)
88
90
  end
89
91
  end
90
92
  end
@@ -1,3 +1,3 @@
1
1
  module ObjectSugar
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Robert Zotter