Class: Marameters::Signatures::Builder
- Inherits:
-
Object
- Object
- Marameters::Signatures::Builder
- Defined in:
- lib/marameters/signatures/builder.rb
Overview
Builds a single parameter for a method’s signature.
Instance Method Summary collapse
- #call(kind, name = nil, default: nil) ⇒ Object
-
#initialize(defaulter: Defaulter) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
Instance Method Details
#call(kind, name = nil, default: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/marameters/signatures/builder.rb', line 12 def call kind, name = nil, default: nil case kind when :req then name when :opt then "#{name} = #{defaulter.call default}" when :rest then "*#{name}" when :nokey then "**nil" when :keyreq then "#{name}:" when :key then "#{name}: #{defaulter.call default}" when :keyrest then "**#{name}" when :block then "&#{name}" else fail ArgumentError, "Wrong kind (#{kind}), name (#{name}), or default (#{default})." end end |