Class: Approximately::DeltaFloat
- Inherits:
-
Struct
- Object
- Struct
- Approximately::DeltaFloat
- Includes:
- Comparable
- Defined in:
- lib/approximately.rb
Overview
This object can be used for float comparisons. When it is instantiaded with a float and a delta it will respond to <=>(another_float) and will return equality if the float it’s being compared to is within the delta
Instance Attribute Summary collapse
-
#delta ⇒ Object
Returns the value of attribute delta.
-
#float ⇒ Object
Returns the value of attribute float.
Instance Method Summary collapse
Instance Attribute Details
#delta ⇒ Object
Returns the value of attribute delta
10 11 12 |
# File 'lib/approximately.rb', line 10 def delta @delta end |
#float ⇒ Object
Returns the value of attribute float
10 11 12 |
# File 'lib/approximately.rb', line 10 def float @float end |
Instance Method Details
#<=>(another) ⇒ Object
17 18 19 20 21 |
# File 'lib/approximately.rb', line 17 def <=>(another) d = (to_f - another.to_f).abs return 0 if d < delta float <=> another.to_f end |
#inspect ⇒ Object
23 24 25 |
# File 'lib/approximately.rb', line 23 def inspect "~%0.8f" % to_f end |
#to_f ⇒ Object
13 14 15 |
# File 'lib/approximately.rb', line 13 def to_f float.to_f end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/approximately.rb', line 27 def to_s inspect end |