Class: Surrogate::ArgumentErrorizer
- Inherits:
-
Object
- Object
- Surrogate::ArgumentErrorizer
- Defined in:
- lib/surrogate/argument_errorizer.rb
Overview
Give it a name and lambda, it will raise an argument error if they don’t match, without actually invoking the method. Its error message includes the signature of the message (maybe should also show what was passed in?)
Instance Attribute Summary collapse
-
#empty_lambda ⇒ Object
Returns the value of attribute empty_lambda.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, lambda_or_method) ⇒ ArgumentErrorizer
constructor
A new instance of ArgumentErrorizer.
- #match!(*args) ⇒ Object
Constructor Details
#initialize(name, lambda_or_method) ⇒ ArgumentErrorizer
Returns a new instance of ArgumentErrorizer.
8 9 10 11 |
# File 'lib/surrogate/argument_errorizer.rb', line 8 def initialize(name, lambda_or_method) must_be_lambda_or_method lambda_or_method self.name, self.empty_lambda = name.to_s, lambda_with_same_params_as(lambda_or_method) end |
Instance Attribute Details
#empty_lambda ⇒ Object
Returns the value of attribute empty_lambda.
6 7 8 |
# File 'lib/surrogate/argument_errorizer.rb', line 6 def empty_lambda @empty_lambda end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/surrogate/argument_errorizer.rb', line 6 def name @name end |
Instance Method Details
#match!(*args) ⇒ Object
13 14 15 16 17 |
# File 'lib/surrogate/argument_errorizer.rb', line 13 def match!(*args) empty_lambda.call *args rescue ArgumentError => e raise ArgumentError, e. + " in #{name}(#{lambda_signature empty_lambda})" end |