Class: Ick::GuardWrapper
- Inherits:
-
IdentityWrapper
- Object
- Wrapper
- IdentityWrapper
- Ick::GuardWrapper
- Defined in:
- lib/ick/guard.rb
Instance Method Summary collapse
- #__invoke__(sym, *args, &block) ⇒ Object
- #__rewrap__(new_value) ⇒ Object
-
#initialize(value, default, proc) ⇒ GuardWrapper
constructor
A new instance of GuardWrapper.
Methods inherited from Wrapper
#__invocation__, #__respond_to?, #__value__, is_contagious, is_not_contagious, #method_missing, #respond_to?
Constructor Details
#initialize(value, default, proc) ⇒ GuardWrapper
Returns a new instance of GuardWrapper.
8 9 10 11 12 |
# File 'lib/ick/guard.rb', line 8 def initialize(value, default, proc) @proc = proc @default = default super(value) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ick::Wrapper
Instance Method Details
#__invoke__(sym, *args, &block) ⇒ Object
16 17 18 |
# File 'lib/ick/guard.rb', line 16 def __invoke__(sym, *args, &block) @proc.call(@value, sym) ? super : @default end |
#__rewrap__(new_value) ⇒ Object
13 14 15 |
# File 'lib/ick/guard.rb', line 13 def __rewrap__(new_value) self.__class.new(new_value, @default, @proc) #contagious end |