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
616
617
618
619
620
|
# File 'lib/rubyhacks.rb', line 616
def self.from_hash(hash)
fh = new
hash.each{|k,v| fh[k]=v}
fh
end
|
Instance Method Details
642
643
644
645
646
647
648
649
650
651
|
# File 'lib/rubyhacks.rb', line 642
def [](key)
old_key = self.find{|k, v| (k-key.to_f).abs < Float::EPSILON}
if old_key
return super(old_key[0])
else
return nil
end
end
|
#[]=(key, var) ⇒ Object
631
632
633
634
635
636
637
638
639
640
|
# File 'lib/rubyhacks.rb', line 631
def []=(key, var)
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
|
623
624
625
|
# File 'lib/rubyhacks.rb', line 623
def inspect
"FloatHash.from_hash(#{old_inspect})"
end
|
#pretty_inspect ⇒ Object
627
628
629
|
# File 'lib/rubyhacks.rb', line 627
def pretty_inspect
"FloatHash.from_hash(#{old_pretty_inspect})"
end
|