Module: Evoke::Parameters
- Included in:
- Task
- Defined in:
- lib/evoke/parameters.rb
Overview
Extendable module for providing access to method parameters during runtime.
Instance Method Summary collapse
-
#optional_parameters(method) ⇒ Array
Gets all the optional parameters for a method.
-
#parameter_names(method) ⇒ Array
Parses the parameters for the supplied method into parameters that can be understood by humans.
-
#parameter_size(method) ⇒ Array
Finds the minimum and maximum amount of parameters the supplied method supports.
-
#required_parameters(method) ⇒ Array
Gets all the required parameters for a method.
-
#select_parameters_by_type(method, type) ⇒ Array
Finds all the parameters of a given type for the supplied method.
Instance Method Details
#optional_parameters(method) ⇒ Array
Gets all the optional parameters for a method.
28 29 30 |
# File 'lib/evoke/parameters.rb', line 28 def optional_parameters(method) select_parameters_by_type(method, :opt) end |
#parameter_names(method) ⇒ Array
Key and &block parameters are not supported.
Parses the parameters for the supplied method into parameters that can be understood by humans. The method names are capitalized. Optional parameters are surrounded in brackets.
64 65 66 |
# File 'lib/evoke/parameters.rb', line 64 def parameter_names(method) method.parameters.map { |type, name| parameter_name(method, type, name) } end |
#parameter_size(method) ⇒ Array
Finds the minimum and maximum amount of parameters the supplied method supports.
9 10 11 12 13 14 |
# File 'lib/evoke/parameters.rb', line 9 def parameter_size(method) req_size = required_parameters(method).size opt_size = optional_parameters(method).size [req_size, req_size + opt_size] end |
#required_parameters(method) ⇒ Array
Gets all the required parameters for a method.
20 21 22 |
# File 'lib/evoke/parameters.rb', line 20 def required_parameters(method) select_parameters_by_type(method, :req) end |
#select_parameters_by_type(method, type) ⇒ Array
Finds all the parameters of a given type for the supplied method.
50 51 52 53 |
# File 'lib/evoke/parameters.rb', line 50 def select_parameters_by_type(method, type) args = method.parameters.select { |param| param[0] == type } args.map { |arg| arg[1] } end |