class FloatHash
Public Class Methods
from_hash(hash)
click to toggle source
# File lib/rubyhacks.rb, line 625 def self.from_hash(hash) fh = new hash.each{|k,v| fh[k]=v} fh end
Public Instance Methods
[](key)
click to toggle source
Calls superclass method
# File lib/rubyhacks.rb, line 651 def [](key) # # # super(key.to_f) # raise TypeError unless key.class == Float #old_key = self.find{|k, v| (k-key.to_f).abs < Float::EPSILON} raise TypeError unless key.kind_of? Numeric old_key = self.keys.inject{|o, n| ((o-key).abs < (n-key).abs) ? o : n } if old_key return super(old_key) else return nil end end
[]=(key, var)
click to toggle source
Calls superclass method
# File lib/rubyhacks.rb, line 640 def []=(key, var) # super(key.to_f, var) raise TypeError unless key.kind_of? Numeric old_key = self.find{|k, v| (k-key.to_f).abs < Float::EPSILON} if old_key super(old_key[0].to_f, var) else super(key.to_f, var) end end
inspect()
click to toggle source
# File lib/rubyhacks.rb, line 632 def inspect "FloatHash.from_hash(#{old_inspect})" end
pretty_inspect()
click to toggle source
# File lib/rubyhacks.rb, line 636 def pretty_inspect "FloatHash.from_hash(#{old_pretty_inspect})" end