Module: Kl::Primitives::Arithmetic
- Included in:
- Environment
- Defined in:
- lib/kl/primitives/arithmetic.rb
Instance Method Summary collapse
- #*(a, b) ⇒ Object
- #+(a, b) ⇒ Object
- #-(a, b) ⇒ Object
- #/(a, b) ⇒ Object
- #<(a, b) ⇒ Object
- #<=(a, b) ⇒ Object
- #>(a, b) ⇒ Object
- #>=(a, b) ⇒ Object
- #number?(a) ⇒ Boolean
Instance Method Details
#*(a, b) ⇒ Object
16 17 18 19 20 |
# File 'lib/kl/primitives/arithmetic.rb', line 16 def *(a, b) raise ::Kl::Error, "#{a} is not a number" unless a.kind_of? Numeric raise ::Kl::Error, "#{b} is not a number" unless b.kind_of? Numeric a * b end |
#+(a, b) ⇒ Object
4 5 6 7 8 |
# File 'lib/kl/primitives/arithmetic.rb', line 4 def +(a, b) raise ::Kl::Error, "#{a} is not a number" unless a.kind_of? Numeric raise ::Kl::Error, "#{b} is not a number" unless b.kind_of? Numeric a + b end |
#-(a, b) ⇒ Object
10 11 12 13 14 |
# File 'lib/kl/primitives/arithmetic.rb', line 10 def -(a, b) raise ::Kl::Error, "#{a} is not a number" unless a.kind_of? Numeric raise ::Kl::Error, "#{b} is not a number" unless b.kind_of? Numeric a - b end |
#/(a, b) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/kl/primitives/arithmetic.rb', line 22 def /(a, b) raise ::Kl::Error, "#{a} is not a number" unless a.kind_of? Numeric raise ::Kl::Error, "#{b} is not a number" unless b.kind_of? Numeric if a.kind_of?(Fixnum) && b.kind_of?(Fixnum) && a % b != 0 a = a.to_f end a / b end |
#<(a, b) ⇒ Object
37 38 39 40 41 |
# File 'lib/kl/primitives/arithmetic.rb', line 37 def <(a, b) raise ::Kl::Error, "#{a} is not a number" unless a.kind_of? Numeric raise ::Kl::Error, "#{b} is not a number" unless b.kind_of? Numeric a < b end |
#<=(a, b) ⇒ Object
49 50 51 52 53 |
# File 'lib/kl/primitives/arithmetic.rb', line 49 def <=(a, b) raise ::Kl::Error, "#{a} is not a number" unless a.kind_of? Numeric raise ::Kl::Error, "#{b} is not a number" unless b.kind_of? Numeric a <= b end |
#>(a, b) ⇒ Object
31 32 33 34 35 |
# File 'lib/kl/primitives/arithmetic.rb', line 31 def >(a, b) raise ::Kl::Error, "#{a} is not a number" unless a.kind_of? Numeric raise ::Kl::Error, "#{b} is not a number" unless b.kind_of? Numeric a > b end |
#>=(a, b) ⇒ Object
43 44 45 46 47 |
# File 'lib/kl/primitives/arithmetic.rb', line 43 def >=(a, b) raise ::Kl::Error, "#{a} is not a number" unless a.kind_of? Numeric raise ::Kl::Error, "#{b} is not a number" unless b.kind_of? Numeric a >= b end |
#number?(a) ⇒ Boolean
55 56 57 |
# File 'lib/kl/primitives/arithmetic.rb', line 55 def number?(a) a.kind_of?(Numeric) end |