123456789_123456789_123456789_123456789_123456789_

Class: RBS::Types::Variable

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/rbs/types.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name:, location:) ⇒ Variable

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 107

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

Class Method Details

.build(v)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 136

def self.build(v)
  case v
  when Symbol
    new(name: v, location: nil)
  when Array
    v.map {|x| new(name: x, location: nil) }
  end
end

.fresh(v = :T)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 146

def self.fresh(v = :T)
  @@count = @@count + 1
  new(name: :"#{v}@#{@@count}", location: nil)
end

Instance Attribute Details

#location (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 103

attr_reader :location

#name (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 102

attr_reader :name

Instance Method Details

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

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 112

def ==(other)
  other.is_a?(Variable) && other.name == name
end

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 116

alias eql? ==

#free_variables(set = Set.new)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 122

def free_variables(set = Set.new)
  set.tap do
    set << name
  end
end

#hash

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 118

def hash
  self.class.hash ^ name.hash
end

#sub(s)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 132

def sub(s)
  s.apply(self)
end

#to_json(state = _ = nil)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 128

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

#to_s(level = 0)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 151

def to_s(level = 0)
  name.to_s
end