Class: Streamer::Functors::Divide
- Defined in:
- lib/streamer/functors/divide.rb
Overview
Divide divides two terms
Instance Attribute Summary
Attributes inherited from Functor
Instance Method Summary collapse
Methods inherited from Functor
#class_name, #initialize, #type_name
Constructor Details
This class inherits a constructor from Streamer::Functors::Functor
Instance Method Details
#call ⇒ Object
5 6 7 |
# File 'lib/streamer/functors/divide.rb', line 5 def call divide end |
#divide ⇒ Object
9 10 11 12 13 14 |
# File 'lib/streamer/functors/divide.rb', line 9 def divide terms = numerify(.fetch(:terms)) fail 'Streamer::Functor# divide: too many terms' if terms.size > 2 return 0.0 if terms.any? { |t| t.to_f == 0.0 } terms[0].to_f / terms[1].to_f end |