Class: YARP::Comment

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

Overview

This represents a comment that was encountered during parsing.

Constant Summary collapse

TYPES =
[:inline, :embdoc, :__END__]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, location) ⇒ Comment

Returns a new instance of Comment.



150
151
152
153
# File 'lib/yarp.rb', line 150

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



148
149
150
# File 'lib/yarp.rb', line 148

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



148
149
150
# File 'lib/yarp.rb', line 148

def type
  @type
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



155
156
157
# File 'lib/yarp.rb', line 155

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

#inspectObject



164
165
166
# File 'lib/yarp.rb', line 164

def inspect
  "#<YARP::Comment @type=#{@type.inspect} @location=#{@location.inspect}>"
end

#trailing?Boolean

Returns true if the comment happens on the same line as other code and false if the comment is by itself

Returns:

  • (Boolean)


160
161
162
# File 'lib/yarp.rb', line 160

def trailing?
  type == :inline && !location.start_line_slice.strip.empty?
end