Class: RBS::Types::Literal
- Inherits:
-
Object
- Object
- RBS::Types::Literal
- Includes:
- EmptyEachType, NoFreeVariables, NoSubst, NoTypeName
- Defined in:
- lib/rbs/types.rb
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
-
#literal ⇒ Object
readonly
Returns the value of attribute literal.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #has_classish_type? ⇒ Boolean
- #has_self_type? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(literal:, location:) ⇒ Literal
constructor
A new instance of Literal.
- #to_json(state = _ = nil) ⇒ Object
- #to_s(level = 0) ⇒ Object
- #with_nonreturn_void? ⇒ Boolean
Methods included from NoTypeName
Methods included from EmptyEachType
Methods included from NoSubst
Methods included from NoFreeVariables
Constructor Details
#initialize(literal:, location:) ⇒ Literal
Returns a new instance of Literal.
1486 1487 1488 1489 |
# File 'lib/rbs/types.rb', line 1486 def initialize(literal:, location:) @literal = literal @location = location end |
Instance Attribute Details
#literal ⇒ Object (readonly)
Returns the value of attribute literal.
1483 1484 1485 |
# File 'lib/rbs/types.rb', line 1483 def literal @literal end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
1484 1485 1486 |
# File 'lib/rbs/types.rb', line 1484 def location @location end |
Class Method Details
.unescape_string(string, is_double_quote) ⇒ Object
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 |
# File 'lib/rbs/types.rb', line 1542 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?
1491 1492 1493 |
# File 'lib/rbs/types.rb', line 1491 def ==(other) other.is_a?(Literal) && other.literal == literal end |
#has_classish_type? ⇒ Boolean
1518 1519 1520 |
# File 'lib/rbs/types.rb', line 1518 def has_classish_type? false end |
#has_self_type? ⇒ Boolean
1514 1515 1516 |
# File 'lib/rbs/types.rb', line 1514 def has_self_type? false end |
#hash ⇒ Object
1497 1498 1499 |
# File 'lib/rbs/types.rb', line 1497 def hash self.class.hash ^ literal.hash end |
#to_json(state = _ = nil) ⇒ Object
1506 1507 1508 |
# File 'lib/rbs/types.rb', line 1506 def to_json(state = _ = nil) { class: :literal, literal: literal.inspect, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
1510 1511 1512 |
# File 'lib/rbs/types.rb', line 1510 def to_s(level = 0) literal.inspect end |
#with_nonreturn_void? ⇒ Boolean
1522 1523 1524 |
# File 'lib/rbs/types.rb', line 1522 def with_nonreturn_void? false end |