Class: Steep::TypeName::Class

Inherits:
Base
  • Object
show all
Defined in:
lib/steep/type_name.rb

Constant Summary collapse

NOTHING =
Object.new

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Instance Method Summary collapse

Constructor Details

#initialize(name:, constructor:) ⇒ Class

Returns a new instance of Class.



51
52
53
54
# File 'lib/steep/type_name.rb', line 51

def initialize(name:, constructor:)
  super(name: name)
  @constructor = constructor
end

Instance Attribute Details

#constructorObject (readonly)

Returns the value of attribute constructor.



36
37
38
# File 'lib/steep/type_name.rb', line 36

def constructor
  @constructor
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
# File 'lib/steep/type_name.rb', line 56

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

#hashObject



60
61
62
# File 'lib/steep/type_name.rb', line 60

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

#map_module_nameObject



74
75
76
# File 'lib/steep/type_name.rb', line 74

def map_module_name
  self.class.new(name: yield(name), constructor: constructor)
end

#to_sObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/steep/type_name.rb', line 38

def to_s
  k = case constructor
      when nil
        ""
      when true
        " constructor"
      when false
        " noconstructor"
      end

  "#{name}.class#{k}"
end

#updated(constructor: NOTHING) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/steep/type_name.rb', line 66

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

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