Class: MaybeDelegator
Overview
Invokes methods on a wrapped object, if that object is truthy.
Instance Method Summary collapse
-
#initialize(o) ⇒ MaybeDelegator
constructor
Creates a new MaybeDelegator, wrapping
o
. -
#maybe ⇒ Object
Returns this MaybeDelegator object.
-
#method_missing(*a, &b) ⇒ Object
Calls the method on @o if it’s truthy.
Constructor Details
permalink #initialize(o) ⇒ MaybeDelegator
Creates a new MaybeDelegator, wrapping o
9 10 11 |
# File 'lib/mug/maybe.rb', line 9 def initialize o @o = o end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
permalink #method_missing(*a, &b) ⇒ Object
Calls the method on @o if it’s truthy.
21 22 23 |
# File 'lib/mug/maybe.rb', line 21 def method_missing *a, &b #:nodoc: @o && @o.send(*a, &b) end |
Instance Method Details
permalink #maybe ⇒ Object
Returns this MaybeDelegator object.
16 17 18 |
# File 'lib/mug/maybe.rb', line 16 def maybe self end |