Module: Tins::MethodDescription

Defined in:
lib/tins/method_description.rb

Defined Under Namespace

Classes: Parameters, Signature

Instance Method Summary collapse

Instance Method Details

#description(style: :namespace) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/tins/method_description.rb', line 106

def description(style: :namespace)
  valid_styles = %i[ namespace name parameters ]
  valid_styles.include?(style) or
    raise ArgumentError,
    "style has to be one of #{valid_styles * ', '}"
  if respond_to?(:parameters)
    generated_name = 'x0'
    parameter_array = parameters.map { |p_type, p_name|
      unless p_name
        generated_name = generated_name.succ
        p_name = generated_name
      end
      Parameters.build(p_type, p_name)
    }
    signature = Signature.new(*parameter_array)
    if style == :parameters
      return signature
    end
  end
  result = ''
  if style == :namespace
    if owner <= Module
      result << receiver.to_s << ?. # XXX Better to use owner here as well?
    else
      result << owner.name.to_s << ?#
    end
  end
  if %i[ namespace name ].include?(style)
    result << name.to_s << '('
  end
  result << (signature || arity).to_s
  if %i[ namespace name ].include?(style)
    result << ?)
  end
  result
end

#signatureObject



102
103
104
# File 'lib/tins/method_description.rb', line 102

def signature
  description style: :parameters
end