Class: LibRubyParser::Nodes::Sym
- Inherits:
-
LibRubyParser::Node
- Object
- LibRubyParser::Node
- LibRubyParser::Nodes::Sym
- 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
-
#begin_l ⇒ Loc?
readonly
Location of the symbol begin.
-
#end_l ⇒ Loc?
readonly
Location of the symbol end.
-
#expression_l ⇒ Loc
readonly
Location of the full expression.
-
#name ⇒ String
readonly
Value of the symbol literal.
Instance Attribute Details
#begin_l ⇒ Loc? (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]
)
3977 3978 3979 |
# File 'lib/lib-ruby-parser/nodes.rb', line 3977 def begin_l @begin_l end |
#end_l ⇒ Loc? (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]
)
3988 3989 3990 |
# File 'lib/lib-ruby-parser/nodes.rb', line 3988 def end_l @end_l end |
#expression_l ⇒ Loc (readonly)
Location of the full expression
:foo
~~~~
{ foo: 1 }
~~~~
%i[foo]
~~~
4003 4004 4005 |
# File 'lib/lib-ruby-parser/nodes.rb', line 4003 def expression_l @expression_l end |
#name ⇒ String (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.
3966 3967 3968 |
# File 'lib/lib-ruby-parser/nodes.rb', line 3966 def name @name end |