Module: Wrong::CloseTo

Included in:
Helpers
Defined in:
lib/wrong/close_to.rb

Instance Method Summary collapse

Instance Method Details

#close_to?(other, tolerance = 0.001) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
# File 'lib/wrong/close_to.rb', line 3

def close_to?(other, tolerance = 0.001)
  if respond_to? :to_f
    (self.to_f - other.to_f).abs < tolerance
  elsif respond_to? :to_time
    self.to_time.close_to?( other.to_time, tolerance)
  end
end