Sha256: 4ae9eab6240afdd48809ac311203839f51e203613f79eb24058cf35c64289012
Contents?: true
Size: 1.79 KB
Versions: 13
Compression:
Stored size: 1.79 KB
Contents
module Kl module Primitives module Arithmetic 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 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 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 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 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 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 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 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 def number?(a) a.kind_of?(Numeric) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems