Class: MaybeDelegator

Inherits:
Object show all
Defined in:
lib/mug/maybe.rb

Overview

Invokes methods on a wrapped object, if that object is truthy.

Instance Method Summary collapse

Constructor Details

#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

#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

#maybeObject

Returns this MaybeDelegator object.



16
17
18
# File 'lib/mug/maybe.rb', line 16

def maybe
	self
end