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

Inherits:
Object
  • Object
show all
Includes:
EmptyEachType, NoFreeVariables, NoSubst
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 EmptyEachType

#each_type

Methods included from NoSubst

#sub

Methods included from NoFreeVariables

#free_variables

Constructor Details

#initialize(location:) ⇒ Base

Returns a new instance of Base.



29
30
31
# File 'lib/rbs/types.rb', line 29

def initialize(location:)
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



27
28
29
# File 'lib/rbs/types.rb', line 27

def location
  @location
end

Instance Method Details

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



33
34
35
# File 'lib/rbs/types.rb', line 33

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

#hashObject



37
38
39
# File 'lib/rbs/types.rb', line 37

def hash
  self.class.hash
end

#to_json(*a) ⇒ Object



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

def to_json(*a)
  klass = to_s.to_sym
  { class: klass, location: location }.to_json(*a)
end

#to_s(level = 0) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rbs/types.rb', line 52

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: #{type.inspect}"
  end
end