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

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

Direct Known Subclasses

Alias, Instance, Interface

Instance Attribute Summary collapse

Attributes inherited from Base

#location, #name

Instance Method Summary collapse

Methods included from Helper::ChildrenLevel

#level_of_children

Constructor Details

#initialize(name:, args:, location: nil) ⇒ Applying

Returns a new instance of Applying.



30
31
32
33
# File 'lib/steep/ast/types/name.rb', line 30

def initialize(name:, args:, location: nil)
  super(name: name, location: location)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



28
29
30
# File 'lib/steep/ast/types/name.rb', line 28

def args
  @args
end

Instance Method Details

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



35
36
37
38
39
# File 'lib/steep/ast/types/name.rb', line 35

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

#free_variablesObject



65
66
67
68
69
# File 'lib/steep/ast/types/name.rb', line 65

def free_variables
  args.each.with_object(Set.new) do |type, vars|
    vars.merge(type.free_variables)
  end
end

#hashObject



43
44
45
# File 'lib/steep/ast/types/name.rb', line 43

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

#levelObject



73
74
75
# File 'lib/steep/ast/types/name.rb', line 73

def level
  [0] + level_of_children(args)
end

#subst(s) ⇒ Object



59
60
61
62
63
# File 'lib/steep/ast/types/name.rb', line 59

def subst(s)
  self.class.new(location: location,
                 name: name,
                 args: args.map {|a| a.subst(s) })
end

#to_sObject



47
48
49
50
51
52
53
# File 'lib/steep/ast/types/name.rb', line 47

def to_s
  if args.empty?
    "#{name}"
  else
    "#{name}[#{args.join(", ")}]"
  end
end

#with_location(new_location) ⇒ Object



55
56
57
# File 'lib/steep/ast/types/name.rb', line 55

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