Sha256: 8a859ea5e85460cfe83e426c1e5949797312759837f2311d81eca5be61795fd6

Contents?: true

Size: 542 Bytes

Versions: 3

Compression:

Stored size: 542 Bytes

Contents

require_relative 'identity'

module Basic101

  class BinaryOperation

    include Identity

    def initialize(operator, right)
      @operator = operator
      @right = right
    end

    def operate(left, runtime)
      if @operator.is_a?(Symbol)
        left_value = left.eval(runtime)
        right_value = @right.eval(runtime)
        left_value.public_send(@operator, right_value)
      else
        @operator.operate(left, @right, runtime)
      end
    end

    protected

    def state
      [@operator, @right]
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
basic101-0.4.0 lib/basic101/binary_operation.rb
basic101-0.2.0 lib/basic101/binary_operation.rb
basic101-0.1.0 lib/basic101/binary_operation.rb