Module: Tins::MethodDescription
- Defined in:
- lib/tins/method_description.rb
Overview
Provides methods for describing method signatures and parameters.
This module is designed to be included in method objects to provide introspection capabilities, particularly useful for generating documentation or debugging method signatures.
Defined Under Namespace
Classes: Parameters, Signature
Instance Method Summary collapse
-
#description(style: :namespace) ⇒ String, Signature
Generates a human-readable description of the method.
-
#signature ⇒ Signature
Retrieves the signature of the method this module is included in.
Instance Method Details
#description(style: :namespace) ⇒ String, Signature
Generates a human-readable description of the method.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/tins/method_description.rb', line 189 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 << ?. 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 |
#signature ⇒ Signature
Retrieves the signature of the method this module is included in.
181 182 183 |
# File 'lib/tins/method_description.rb', line 181 def signature description style: :parameters end |