Class: Be::Delegator
- Inherits:
- BasicObject
- Defined in:
- lib/be/delegator.rb
Overview
Delegator acts as the go-between between the subjunctive call and the Assertor.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #equal?(other) ⇒ Boolean
-
#initialize(criteria = {}) ⇒ Delegator
constructor
Initialize new Delegator.
- #method_missing(name, *args, &blk) ⇒ Object
-
#to_assertor ⇒ Object
Convert to Assertor.
Constructor Details
#initialize(criteria = {}) ⇒ Delegator
Initialize new Delegator.
11 12 13 14 |
# File 'lib/be/delegator.rb', line 11 def initialize(criteria={}) @criteria = criteria @messages = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &blk) ⇒ Object
32 33 34 35 |
# File 'lib/be/delegator.rb', line 32 def method_missing(name, *args, &blk) @messages << [name, args, blk] self end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 40 |
# File 'lib/be/delegator.rb', line 37 def ==(other) @messages << [:==, [other], nil] self end |
#equal?(other) ⇒ Boolean
42 43 44 45 |
# File 'lib/be/delegator.rb', line 42 def equal?(other) @messages << [:==, [other], nil] self end |
#to_assertor ⇒ Object
Convert to Assertor. If ‘@messages` is empty then defaults to calling method given by `criteria` or `#==` failing that.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/be/delegator.rb', line 21 def to_assertor if @messages.empty? default = @criteria.delete(:default) || :== measure = @criteria.delete(:measure) = [[default, [measure], nil]] Assertor.new(, @criteria) else Assertor.new(@messages, @criteria) end end |