Sha256: ec63e87950afca0787163740df1d75626862db66ece6cf0ca086ed101be85c59

Contents?: true

Size: 919 Bytes

Versions: 21

Compression:

Stored size: 919 Bytes

Contents

class Code
  class Node
    class Operation < Node
      class Operator < Node
        attr_reader :operator, :statement

        def initialize(parsed)
          @operator = parsed.delete(:operator)
          @statement = Node::Statement.new(parsed.delete(:statement))
        end
      end

      def initialize(parsed)
        @first = Node::Statement.new(parsed.delete(:first))
        @others =
          parsed
            .delete(:others)
            .map { |operator| Node::Operation::Operator.new(operator) }

        super(parsed)
      end

      def evaluate(**args)
        first = @first.evaluate(**args)

        @others.reduce(first) do |left, right|
          statement = right.statement.evaluate(**args)

          left.call(
            operator: right.operator,
            arguments: [::Code::Object::Argument.new(statement)],
            **args
          )
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
template-ruby-0.5.6 lib/code/node/operation.rb
language-ruby-0.5.6 lib/code/node/operation.rb
code-ruby-0.5.6 lib/code/node/operation.rb
template-ruby-0.5.5 lib/code/node/operation.rb
language-ruby-0.5.5 lib/code/node/operation.rb
code-ruby-0.5.5 lib/code/node/operation.rb
template-ruby-0.5.4 lib/code/node/operation.rb
language-ruby-0.5.4 lib/code/node/operation.rb
code-ruby-0.5.4 lib/code/node/operation.rb
template-ruby-0.5.3 lib/code/node/operation.rb
language-ruby-0.5.3 lib/code/node/operation.rb
code-ruby-0.5.3 lib/code/node/operation.rb
template-ruby-0.5.2 lib/code/node/operation.rb
language-ruby-0.5.2 lib/code/node/operation.rb
code-ruby-0.5.2 lib/code/node/operation.rb
language-ruby-0.5.1 lib/code/node/operation.rb
template-ruby-0.5.1 lib/code/node/operation.rb
code-ruby-0.5.1 lib/code/node/operation.rb
template-ruby-0.5.0 lib/code/node/operation.rb
language-ruby-0.5.0 lib/code/node/operation.rb