Class: Gelauto::MethodDef

Inherits:
Object
  • Object
show all
Defined in:
lib/gelauto/method_def.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, args, nesting, return_types = TypeSet.new) ⇒ MethodDef

Returns a new instance of MethodDef.



7
8
9
10
11
12
# File 'lib/gelauto/method_def.rb', line 7

def initialize(name, args, nesting, return_types = TypeSet.new)
  @name = name
  @args = ArgList.new(args.map { |arg| Var.new(arg) })
  @nesting = nesting
  @return_types = return_types
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/gelauto/method_def.rb', line 5

def args
  @args
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gelauto/method_def.rb', line 5

def name
  @name
end

#nestingObject (readonly)

Returns the value of attribute nesting.



5
6
7
# File 'lib/gelauto/method_def.rb', line 5

def nesting
  @nesting
end

#return_typesObject (readonly)

Returns the value of attribute return_types.



5
6
7
# File 'lib/gelauto/method_def.rb', line 5

def return_types
  @return_types
end

Instance Method Details

#to_rbiObject



30
31
32
# File 'lib/gelauto/method_def.rb', line 30

def to_rbi
  "#{to_sig}\ndef #{name}; end"
end

#to_sigObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gelauto/method_def.rb', line 14

def to_sig
  components = []

  unless args.empty?
    components << "params(#{args.to_sig})"
  end

  if name == :initialize
    components << 'void'
  else
    components << "returns(#{return_types.to_sig})"
  end

  "sig { #{components.join('.')} }"
end