lib/ruby/extensions/methoded_hash.rb in ruby-mext-0.16.1 vs lib/ruby/extensions/methoded_hash.rb in ruby-mext-0.16.2
- old
+ new
@@ -13,12 +13,12 @@
duplicate_hash(h)
self
end
def []=(key, value)
- common_methodizer(key)
super
+ common_methodizer(key)
end
private
def duplicate_hash(arg)
@@ -47,10 +47,12 @@
# methods. Please note that "methodization" will only happen if the
# class does not already respond to a normalized key method.
#
def methodize(key)
nk = normalize_key(key)
- define_singleton_method(nk) { self[key] } unless self.respond_to?(nk)
+ iname = ('@' + nk.to_s).to_sym
+ self.instance_variable_set(iname, self[key])
+ define_singleton_method(nk) { self.instance_variable_get(iname) } unless self.respond_to?(nk)
end
def normalize_key(key)
ek = key.to_s.gsub(/\W/, '_')
ek.to_sym