Sha256: 94efca72c4726db71e319ce754eba3f82fa9d8a06825b323e79c0b176207786c
Contents?: true
Size: 964 Bytes
Versions: 3
Compression:
Stored size: 964 Bytes
Contents
module Dentaku class BinaryOperation attr_reader :left, :right def initialize(left, right) @left = left @right = right end def pow; [:numeric, left ** right]; end def add; [:numeric, left + right]; end def subtract; [:numeric, left - right]; end def multiply; [:numeric, left * right]; end def divide quotient, remainder = left.divmod(right) return [:numeric, quotient] if remainder == 0 [:numeric, left.to_f / right.to_f] end def mod; [:numeric, left % right]; end def le; [:logical, left <= right]; end def ge; [:logical, left >= right]; end def lt; [:logical, left < right]; end def gt; [:logical, left > right]; end def ne; [:logical, left != right]; end def eq; [:logical, left == right]; end def and; [:logical, left && right]; end def or; [:logical, left || right]; end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dentaku-1.0.0 | lib/dentaku/binary_operation.rb |
dentaku-0.2.14 | lib/dentaku/binary_operation.rb |
dentaku-0.2.13 | lib/dentaku/binary_operation.rb |