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.



1363
1364
1365
1366
# File 'lib/rbs/types.rb', line 1363

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

Instance Attribute Details

#literalObject (readonly)

Returns the value of attribute literal.



1360
1361
1362
# File 'lib/rbs/types.rb', line 1360

def literal
  @literal
end

#locationObject (readonly)

Returns the value of attribute location.



1361
1362
1363
# File 'lib/rbs/types.rb', line 1361

def location
  @location
end

Class Method Details

.unescape_string(string, is_double_quote) ⇒ Object



1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
# File 'lib/rbs/types.rb', line 1419

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?



1368
1369
1370
# File 'lib/rbs/types.rb', line 1368

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

#has_classish_type?Boolean

Returns:

  • (Boolean)


1395
1396
1397
# File 'lib/rbs/types.rb', line 1395

def has_classish_type?
  false
end

#has_self_type?Boolean

Returns:

  • (Boolean)


1391
1392
1393
# File 'lib/rbs/types.rb', line 1391

def has_self_type?
  false
end

#hashObject



1374
1375
1376
# File 'lib/rbs/types.rb', line 1374

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

#to_json(state = _ = nil) ⇒ Object



1383
1384
1385
# File 'lib/rbs/types.rb', line 1383

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

#to_s(level = 0) ⇒ Object



1387
1388
1389
# File 'lib/rbs/types.rb', line 1387

def to_s(level = 0)
  literal.inspect
end

#with_nonreturn_void?Boolean

Returns:

  • (Boolean)


1399
1400
1401
# File 'lib/rbs/types.rb', line 1399

def with_nonreturn_void?
  false
end