Class: Steep::AST::Types::Name::Class

Inherits:
Base
  • Object
show all
Defined in:
lib/steep/ast/types/name.rb

Constant Summary collapse

NOTHING =
::Object.new

Instance Attribute Summary collapse

Attributes inherited from Base

#location, #name

Instance Method Summary collapse

Methods inherited from Base

#free_variables, #level, #subst

Constructor Details

#initialize(name:, constructor:, location: nil) ⇒ Class

Returns a new instance of Class.



81
82
83
84
85
# File 'lib/steep/ast/types/name.rb', line 81

def initialize(name:, constructor:, location: nil)
  raise "Name should be a module name: #{name.inspect}" unless name.is_a?(Names::Module)
  super(name: name, location: location)
  @constructor = constructor
end

Instance Attribute Details

#constructorObject (readonly)

Returns the value of attribute constructor.



79
80
81
# File 'lib/steep/ast/types/name.rb', line 79

def constructor
  @constructor
end

Instance Method Details

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



87
88
89
90
91
# File 'lib/steep/ast/types/name.rb', line 87

def ==(other)
  other.class == self.class &&
    other.name == name &&
    other.constructor == constructor
end

#hashObject



95
96
97
# File 'lib/steep/ast/types/name.rb', line 95

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

#to_instance(*args) ⇒ Object



115
116
117
# File 'lib/steep/ast/types/name.rb', line 115

def to_instance(*args)
  Instance.new(name: name, args: args)
end

#to_sObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/steep/ast/types/name.rb', line 99

def to_s
  k = case constructor
      when true
        " constructor"
      when false
        " noconstructor"
      when nil
        ""
      end
  "singleton(#{name.to_s})"
end

#updated(constructor: NOTHING) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/steep/ast/types/name.rb', line 121

def updated(constructor: NOTHING)
  if NOTHING == constructor
    constructor = self.constructor
  end

  self.class.new(name: name, constructor: constructor, location: location)
end

#with_location(new_location) ⇒ Object



111
112
113
# File 'lib/steep/ast/types/name.rb', line 111

def with_location(new_location)
  self.class.new(name: name, constructor: constructor, location: new_location)
end