Class: MustBe::Proxy
Instance Method Summary collapse
-
#initialize(delegate, assertion = :must) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(symbol, *args, &block) ⇒ Object
Constructor Details
#initialize(delegate, assertion = :must) ⇒ Proxy
Returns a new instance of Proxy.
13 14 15 16 17 18 19 20 |
# File 'lib/must_be/proxy.rb', line 13 def initialize(delegate, assertion = :must) unless assertion == :must or assertion == :must_not raise ArgumentError, "assertion (#{assertion.inspect}) must be :must or :must_not" end @delegate = delegate @assertion = assertion end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/must_be/proxy.rb', line 22 def method_missing(symbol, *args, &block) result = @delegate.send(symbol, *args, &block) assertion = result ? true : false unless assertion == (@assertion == :must) @delegate.must_notify(@delegate, "#{@assertion}.#{symbol}", args, block) end result end |