Class: RBS::Types::Bases::Base

Inherits:
Object
  • Object
show all
Includes:
EmptyEachType, NoFreeVariables, NoSubst, NoTypeName
Defined in:
lib/rbs/types.rb

Direct Known Subclasses

Any, Bool, Bottom, Class, Instance, Nil, Self, Top, Void

Instance Attribute 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(location:) ⇒ Base

Returns a new instance of Base.



45
46
47
# File 'lib/rbs/types.rb', line 45

def initialize(location:)
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



43
44
45
# File 'lib/rbs/types.rb', line 43

def location
  @location
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



49
50
51
# File 'lib/rbs/types.rb', line 49

def ==(other)
  other.is_a?(self.class)
end

#hashObject



53
54
55
# File 'lib/rbs/types.rb', line 53

def hash
  self.class.hash
end

#to_json(state = _ = nil) ⇒ Object



64
65
66
67
# File 'lib/rbs/types.rb', line 64

def to_json(state = _ = nil)
  klass = to_s.to_sym
  { class: klass, location: location }.to_json(state)
end

#to_s(level = 0) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rbs/types.rb', line 69

def to_s(level = 0)
  case self
  when Types::Bases::Bool
    'bool'
  when Types::Bases::Void
    'void'
  when Types::Bases::Any
    'untyped'
  when Types::Bases::Nil
    'nil'
  when Types::Bases::Top
    'top'
  when Types::Bases::Bottom
    'bot'
  when Types::Bases::Self
    'self'
  when Types::Bases::Instance
    'instance'
  when Types::Bases::Class
    'class'
  else
    raise "Unexpected base type: #{inspect}"
  end
end