Class: NamedParameter::NamedMethod
- Inherits:
-
Object
- Object
- NamedParameter::NamedMethod
- Defined in:
- lib/named_parameter/named_method.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
Instance Method Summary collapse
- #errors_when_called_with(args = {}) ⇒ Object
- #have_a_parameter_like?(arg_name) ⇒ Boolean
-
#initialize(method) ⇒ NamedMethod
constructor
A new instance of NamedMethod.
- #name_of_original ⇒ Object
- #required_parameters ⇒ Object
Constructor Details
#initialize(method) ⇒ NamedMethod
Returns a new instance of NamedMethod.
5 6 7 8 9 10 |
# File 'lib/named_parameter/named_method.rb', line 5 def initialize(method) method.owner.instance_eval do alias_method :"___original_#{method.name}___",method.name.to_sym end @method = method end |
Instance Attribute Details
#method ⇒ Object
Returns the value of attribute method.
3 4 5 |
# File 'lib/named_parameter/named_method.rb', line 3 def method @method end |
Instance Method Details
#errors_when_called_with(args = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/named_parameter/named_method.rb', line 16 def errors_when_called_with(args={}) errors = [] errors += Errors::NotHash.all_when self, :called_with => args if errors.empty? errors += Errors::UndefinedParameters.all_when self, :called_with => args errors += Errors::RequiredParameters.all_when self, :called_with => args end errors end |
#have_a_parameter_like?(arg_name) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/named_parameter/named_method.rb', line 35 def have_a_parameter_like?(arg_name) @method.parameters.any? do |method_parameter| method_parameter[1].to_s == arg_name.to_s end end |
#name_of_original ⇒ Object
12 13 14 |
# File 'lib/named_parameter/named_method.rb', line 12 def name_of_original :"___original_#{@method.name}___" end |
#required_parameters ⇒ Object
29 30 31 32 33 |
# File 'lib/named_parameter/named_method.rb', line 29 def required_parameters @method.parameters.collect do |parameter| parameter.last if parameter.first == :req end.compact end |