Permalink
Browse files

refactor

  • Loading branch information...
1 parent cc9189f commit c777c8259238105179c6e2709ab288671f9c347c @kachick committed Apr 14, 2012
Showing with 14 additions and 11 deletions.
  1. +14 −11 lib/instancevalue.rb
View
@@ -47,48 +47,51 @@ def instance_value_defined?(name)
raise TypeError
end
- if singleton_class.const_defined? :VALUES
- singleton_class::VALUES.has_key? name.to_sym
- else
- singleton_class.const_set :VALUES, {}
- false
- end
+ _values.has_key? name.to_sym
end
def instance_value_get(name)
- instance_value_defined?(name) ? singleton_class::VALUES[name.to_sym] : nil
+ instance_value_defined?(name) ? _values[name.to_sym] : nil
end
def instance_value_set(name, value)
if instance_value_defined? name
raise "the value(#{name}) was already binded"
else
- singleton_class::VALUES[name.to_sym] = value
+ _values[name.to_sym] = value
end
end
def instance_values
- singleton_class::VALUES.keys
+ _values.keys
end
def inspect
super.sub(/>\z/){
- singleton_class::VALUES.map{|name, value|
+ _values.map{|name, value|
" #{name}=#{value.inspect}"
}.join + '>'
}
end
private
+ def _values
+ if singleton_class.const_defined? :VALUES
+ singleton_class::VALUES
+ else
+ singleton_class.const_set :VALUES, {}
+ end
+ end
+
def initialize_copy(original)
singleton_class.const_set :VALUES,
original.singleton_class::VALUES.dup
end
def remove_instance_value(name)
if instance_value_defined? name
- singleton_class::VALUES.delete name.to_sym
+ _values.delete name.to_sym
else
raise NameError
end

0 comments on commit c777c82

Please sign in to comment.