Class: Contracts::Formatters::TypesAST

Inherits:
Object
  • Object
show all
Defined in:
lib/yard-contracts/formatters.rb

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ TypesAST

Returns a new instance of TypesAST


91
92
93
# File 'lib/yard-contracts/formatters.rb', line 91

def initialize(types)
  @types = types[0..-2]
end

Instance Method Details

#resultObject


108
109
110
111
# File 'lib/yard-contracts/formatters.rb', line 108

def result
  # Get the result out of the `param => result` part
  [@types.last.last.last.source, @types.last.last.last]
end

#to_aObject


95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/yard-contracts/formatters.rb', line 95

def to_a
  types = []
  @types.each_with_index do |type, i|
    if i == @types.length-1
      # Get the param out of the `param => result` part
      types << [type.first.first.source, type.first.first]
    else
      types << [type.source, type]
    end
  end
  types
end