Class: FloatHash
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Hash
#+, #expand_bools, #modify, #random, #random_key, #random_value
Class Method Details
.from_hash(hash) ⇒ Object
625
626
627
628
629
|
# File 'lib/rubyhacks.rb', line 625
def self.from_hash(hash)
fh = new
hash.each{|k,v| fh[k]=v}
fh
end
|
Instance Method Details
651
652
653
654
655
656
657
658
659
660
661
662
|
# File 'lib/rubyhacks.rb', line 651
def [](key)
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) ⇒ Object
640
641
642
643
644
645
646
647
648
649
|
# File 'lib/rubyhacks.rb', line 640
def []=(key, 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
|
632
633
634
|
# File 'lib/rubyhacks.rb', line 632
def inspect
"FloatHash.from_hash(#{old_inspect})"
end
|
#pretty_inspect ⇒ Object
636
637
638
|
# File 'lib/rubyhacks.rb', line 636
def pretty_inspect
"FloatHash.from_hash(#{old_pretty_inspect})"
end
|