Class: YARP::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/yarp.rb,
ext/yarp/extension.c

Overview

This represents a token from the Ruby source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, location) ⇒ Token



235
236
237
238
239
# File 'lib/yarp.rb', line 235

def initialize(type, value, location)
  @type = type
  @value = value
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



233
234
235
# File 'lib/yarp.rb', line 233

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



233
234
235
# File 'lib/yarp.rb', line 233

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



233
234
235
# File 'lib/yarp.rb', line 233

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



259
260
261
262
263
# File 'lib/yarp.rb', line 259

def ==(other)
  other.is_a?(Token) &&
    other.type == type &&
    other.value == value
end

#deconstruct_keys(keys) ⇒ Object



241
242
243
# File 'lib/yarp.rb', line 241

def deconstruct_keys(keys)
  { type: type, value: value, location: location }
end

#pretty_print(q) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/yarp.rb', line 245

def pretty_print(q)
  q.group do
    q.text(type.to_s)
    self.location.pretty_print(q)
    q.text("(")
    q.nest(2) do
      q.breakable("")
      q.pp(value)
    end
    q.breakable("")
    q.text(")")
  end
end