Class: LibRubyParser::Nodes::Str
- Inherits:
-
LibRubyParser::Node
- Object
- LibRubyParser::Node
- LibRubyParser::Nodes::Str
- Defined in:
- lib/lib-ruby-parser/nodes.rb
Overview
Represents a plain non-interpolated string literal (e.g. "foo"
)
Instance Attribute Summary collapse
-
#begin_l ⇒ Loc?
readonly
Location of the string begin.
-
#end_l ⇒ Loc?
readonly
Location of the string begin.
-
#expression_l ⇒ Loc
readonly
Location of the full expression.
-
#value ⇒ String
readonly
Value of the string literal.
Instance Attribute Details
#begin_l ⇒ Loc? (readonly)
Location of the string begin
"foo"
~
None
if string literal is a part of the words array (like %w[foo bar baz]
)
3879 3880 3881 |
# File 'lib/lib-ruby-parser/nodes.rb', line 3879 def begin_l @begin_l end |
#end_l ⇒ Loc? (readonly)
Location of the string begin
"foo"
~
None
if string literal is a part of the words array (like %w[foo bar baz]
)
3890 3891 3892 |
# File 'lib/lib-ruby-parser/nodes.rb', line 3890 def end_l @end_l end |
#expression_l ⇒ Loc (readonly)
Location of the full expression
"foo"
~~~~~
3899 3900 3901 |
# File 'lib/lib-ruby-parser/nodes.rb', line 3899 def expression_l @expression_l end |
#value ⇒ String (readonly)
Value of the string 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 string value.
3868 3869 3870 |
# File 'lib/lib-ruby-parser/nodes.rb', line 3868 def value @value end |