Class: RBS::Types::Literal

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NoTypeName

#map_type_name

Methods included from EmptyEachType

#each_type, #map_type

Methods included from NoSubst

#sub

Methods included from NoFreeVariables

#free_variables

Constructor Details

#initialize(literal:, location:) ⇒ Literal

Returns a new instance of Literal.



1524
1525
1526
1527
# File 'lib/rbs/types.rb', line 1524

def initialize(literal:, location:)
  @literal = literal
  @location = location
end

Instance Attribute Details

#literalObject (readonly)

Returns the value of attribute literal.



1521
1522
1523
# File 'lib/rbs/types.rb', line 1521

def literal
  @literal
end

#locationObject (readonly)

Returns the value of attribute location.



1522
1523
1524
# File 'lib/rbs/types.rb', line 1522

def location
  @location
end

Class Method Details

.unescape_string(string, is_double_quote) ⇒ Object



1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
# File 'lib/rbs/types.rb', line 1580

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?



1529
1530
1531
# File 'lib/rbs/types.rb', line 1529

def ==(other)
  other.is_a?(Literal) && other.literal == literal
end

#has_classish_type?Boolean

Returns:

  • (Boolean)


1556
1557
1558
# File 'lib/rbs/types.rb', line 1556

def has_classish_type?
  false
end

#has_self_type?Boolean

Returns:

  • (Boolean)


1552
1553
1554
# File 'lib/rbs/types.rb', line 1552

def has_self_type?
  false
end

#hashObject



1535
1536
1537
# File 'lib/rbs/types.rb', line 1535

def hash
  self.class.hash ^ literal.hash
end

#to_json(state = _ = nil) ⇒ Object



1544
1545
1546
# File 'lib/rbs/types.rb', line 1544

def to_json(state = _ = nil)
  { class: :literal, literal: literal.inspect, location: location }.to_json(state)
end

#to_s(level = 0) ⇒ Object



1548
1549
1550
# File 'lib/rbs/types.rb', line 1548

def to_s(level = 0)
  literal.inspect
end

#with_nonreturn_void?Boolean

Returns:

  • (Boolean)


1560
1561
1562
# File 'lib/rbs/types.rb', line 1560

def with_nonreturn_void?
  false
end