Sha256: bb5a42b69585d9cd0ddd0e2445064c5b9f954c66159345feb86d9ba18cddba92

Contents?: true

Size: 890 Bytes

Versions: 4

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

class Code
  class Node
    class SquareBracket < Node
      def initialize(parsed)
        return if parsed.blank?
        @left = Node::Statement.new(parsed.delete(:left).presence)
        @statements = parsed.delete(:statements).presence || []
        @statements.map! { |statement| Node::Statement.new(statement) }
      end

      def evaluate(**args)
        left = @left&.evaluate(**args) || Object::Nothing.new

        (@statements || []).reduce(left) do |object, statement|
          object.code_fetch(statement.evaluate(**args))
        end
      end

      def resolve(**args)
        left = @left&.resolve(**args) || Object::Nothing.new

        list = Object::IdentifierList.new([left])

        (@statements || []).each do |statement|
          list.code_append(statement.evaluate(**args))
        end

        list
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
code-ruby-0.13.1 lib/code/node/square_bracket.rb
code-ruby-0.13.0 lib/code/node/square_bracket.rb
code-ruby-0.12.0 lib/code/node/square_bracket.rb
code-ruby-0.11.0 lib/code/node/square_bracket.rb