lib/hash.rb in hash_dot-2.0.1 vs lib/hash.rb in hash_dot-2.0.2
- old
+ new
@@ -14,16 +14,12 @@
def method_missing(method, *args)
return super(method, *args) unless to_dot?
prop = create_prop(method)
- if self[prop].nil? && prop_present?(prop)
- self[prop] = self.delete(prop.to_s)
- end
+ super(method, args) && return unless key?(prop)
- super(method, args) and return unless prop_present?(prop)
-
if setter?(method)
self[prop] = args.first
else
self[prop]
end
@@ -36,20 +32,22 @@
hash.keys.each { |key| dotify_hash(hash[key]) if hash[key].is_a?(Hash) }
end
def to_dot?
- self.use_dot_syntax || self.class.use_dot_syntax
+ use_dot_syntax || self.class.use_dot_syntax
end
def setter?(method)
method.last == "="
end
def create_prop(method)
- setter?(method) ? method.chop : method
+ prop = basic_prop_from_method(method)
+
+ key?(prop.to_s) ? prop.to_s : prop
end
- def prop_present?(prop)
- self.has_key?(prop) || self.has_key?(prop.to_s)
+ def basic_prop_from_method(method)
+ setter?(method) ? method.chop : method
end
end