Class: LibRubyParser::Nodes::Sym

Inherits:
LibRubyParser::Node show all
Defined in:
lib/lib-ruby-parser/nodes.rb

Overview

Represents a plain symbol literal (i.e. :foo)

Note that : in { foo: bar } belongs to a pair node.

Instance Attribute Summary collapse

Instance Attribute Details

#begin_lLoc? (readonly)

Location of the symbol begin

:foo
~

None if symbol is a label ({ foo: 1 }) or a part of the symbols array (%i[foo bar baz])

Returns:



3977
3978
3979
# File 'lib/lib-ruby-parser/nodes.rb', line 3977

def begin_l
  @begin_l
end

#end_lLoc? (readonly)

Location of the symbol end

{ 'foo': 1 }
       ~

None if symbol is not a string label (:foo) or a part of the symbols array (%i[foo bar baz])

Returns:



3988
3989
3990
# File 'lib/lib-ruby-parser/nodes.rb', line 3988

def end_l
  @end_l
end

#expression_lLoc (readonly)

Location of the full expression

:foo
~~~~

{ foo: 1 }
  ~~~~

%i[foo]
   ~~~

Returns:



4003
4004
4005
# File 'lib/lib-ruby-parser/nodes.rb', line 4003

def expression_l
  @expression_l
end

#nameString (readonly)

Value of the symbol literal

Note that it's a StringValue, not a String. The reason is that you can get UTF-8 incompatible strings from a valid UTF-8 source using escape sequences like "\xFF"

These "\", "x", "F", "F" chars are valid separately, but together they construct a char with code = 255 that is invalid for UTF-8.

You can use to_string_lossy or to_string methods to get a raw symbol value.

Returns:

  • (String)


3966
3967
3968
# File 'lib/lib-ruby-parser/nodes.rb', line 3966

def name
  @name
end