Class: ReverseParameters::Base

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

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Base

Returns a new instance of Base.

Parameters:

  • input (Proc, Array)


14
15
16
17
18
19
20
21
22
# File 'lib/reverse_parameters.rb', line 14

def initialize(input)
  if input.respond_to?(:to_proc)
    @params = input.to_proc.parameters
  elsif input.respond_to?(:to_ary)
    @params = input.to_ary
  else
    raise ArgumentError.new("Input must be an Array of parameters or a Proc object.")
  end
end

Instance Method Details

#arguments(blocks_as_values: false) ⇒ ReverseParameters::Arguments

Method arguments are the real values passed to (and received by) the function. def my_method(&block) end ReverseParameters.new(method(:my_method)).arguments(blocks_as_values: true).to_s

#=> "block"

# ReverseParameters.new(method(:my_method)).arguments.to_s

#=> "&block"

Parameters:

  • blocks_as_values: (true, false) (defaults to: false)

    express block as variable vs a proc passed to the end of a method.

Returns:



40
41
42
# File 'lib/reverse_parameters.rb', line 40

def arguments(blocks_as_values: false)
  Arguments.new(params, blocks_as_values: blocks_as_values)
end

#parametersReverseParameters::Parameters

Method parameters are the names listed in the function definition.



26
27
28
# File 'lib/reverse_parameters.rb', line 26

def parameters
  Parameters.new(params)
end