Class: MiniRuby::AST::AttributeAccessExpressionNode

Inherits:
ExpressionNode show all
Defined in:
lib/miniruby/ast.rb

Overview

Represents an attribute access expression like ‘foo.bar`

Instance Attribute Summary collapse

Attributes inherited from Node

#span

Instance Method Summary collapse

Constructor Details

#initialize(receiver:, field:, span: Span::ZERO) ⇒ AttributeAccessExpressionNode

: (receiver: ExpressionNode, field: IdentifierNode, ?span: Span) -> void



269
270
271
272
273
# File 'lib/miniruby/ast.rb', line 269

def initialize(receiver:, field:, span: Span::ZERO)
  @span = span
  @receiver = receiver
  @field = field
end

Instance Attribute Details

#fieldObject (readonly)

: IdentifierNode



266
267
268
# File 'lib/miniruby/ast.rb', line 266

def field
  @field
end

#receiverObject (readonly)

: ExpressionNode



263
264
265
# File 'lib/miniruby/ast.rb', line 263

def receiver
  @receiver
end

Instance Method Details

#==(other) ⇒ Object

: (Object other) -> bool



276
277
278
279
280
281
# File 'lib/miniruby/ast.rb', line 276

def ==(other)
  return false unless other.is_a?(AttributeAccessExpressionNode)

  @receiver == other.receiver &&
    @field == other.field
end

#inspect(indent = 0) ⇒ Object

: (?Integer indent) -> String



291
292
293
294
295
296
297
298
299
300
# File 'lib/miniruby/ast.rb', line 291

def inspect(indent = 0)
  buff = String.new
  buff << "#{INDENT_UNIT * indent}(attr"

  buff << "\n" << @receiver.inspect(indent + 1)
  buff << "\n" << @field.inspect(indent + 1)

  buff << ')'
  buff
end

#to_s(indent = 0) ⇒ Object

: (?Integer indent) -> String



285
286
287
# File 'lib/miniruby/ast.rb', line 285

def to_s(indent = 0)
  "#{INDENT_UNIT * indent}#{@receiver}.#{@field}"
end