Class: RBS::Types::Literal
Constant Summary
collapse
- TABLE =
{
"\\a" => "\a",
"\\b" => "\b",
"\\e" => "\033",
"\\f" => "\f",
"\\n" => "\n",
"\\r" => "\r",
"\\s" => " ",
"\\t" => "\t",
"\\v" => "\v",
"\\\"" => "\"",
"\\\'" => "'",
"\\\\" => "\\",
"\\" => ""
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from NoTypeName
#map_type_name
#each_type, #map_type
Methods included from NoSubst
#sub
#free_variables
Methods included from _TypeBase
#each_type, #free_variables, #map_type_name, #sub
Constructor Details
#initialize(literal:, location:) ⇒ Literal
Returns a new instance of Literal.
1576
1577
1578
1579
|
# File 'lib/rbs/types.rb', line 1576
def initialize(literal:, location:)
@literal = literal
@location = location
end
|
Instance Attribute Details
Returns the value of attribute literal.
1573
1574
1575
|
# File 'lib/rbs/types.rb', line 1573
def literal
@literal
end
|
#location ⇒ loc?
Returns the value of attribute location.
1574
1575
1576
|
# File 'lib/rbs/types.rb', line 1574
def location
@location
end
|
Class Method Details
.unescape_string(string, is_double_quote) ⇒ String
Unescape string type body
585
586
587
588
589
590
591
592
593
594
595
596
|
# File 'sig/types.rbs', line 585
def self.unescape_string(string, is_double_quote)
if is_double_quote
string.gsub!(/\\([0-9]{1,3})/) { ($1 || "").to_i(8).chr }
string.gsub!(/\\x([0-9a-f]{1,2})/) { ($1 || "").to_i(16).chr }
string.gsub!(/\\u([0-9a-fA-F]{4})/) { ($1 || "").to_i(16).chr(Encoding::UTF_8) }
string.gsub!(/\\[abefnrstv"'\\]?/, TABLE)
string
else
string.gsub!(/\\['\\]/, TABLE)
string
end
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
1581
1582
1583
|
# File 'lib/rbs/types.rb', line 1581
def ==(other)
other.is_a?(Literal) && other.literal == literal
end
|
#has_classish_type? ⇒ Boolean
1608
1609
1610
|
# File 'lib/rbs/types.rb', line 1608
def has_classish_type?
false
end
|
#has_self_type? ⇒ Boolean
1604
1605
1606
|
# File 'lib/rbs/types.rb', line 1604
def has_self_type?
false
end
|
#hash ⇒ Object
1587
1588
1589
|
# File 'lib/rbs/types.rb', line 1587
def hash
self.class.hash ^ literal.hash
end
|
#to_json(state = nil) ⇒ Object
1596
1597
1598
|
# File 'lib/rbs/types.rb', line 1596
def to_json(state = nil)
{ class: :literal, literal: literal.inspect, location: location }.to_json(state)
end
|
#to_s(level = 0) ⇒ Object
1600
1601
1602
|
# File 'lib/rbs/types.rb', line 1600
def to_s(level = 0)
literal.inspect
end
|
#with_nonreturn_void? ⇒ Boolean
1612
1613
1614
|
# File 'lib/rbs/types.rb', line 1612
def with_nonreturn_void?
false
end
|