class MaybeDelegator

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

Public Class Methods

new(o) click to toggle source

Creates a new MaybeDelegator, wrapping o

# File lib/mug/maybe.rb, line 9
def initialize o
  @o = o
end

Public Instance Methods

maybe() click to toggle source

Returns this MaybeDelegator object.

# File lib/mug/maybe.rb, line 16
def maybe
  self
end
respond_to_missing?(meth, priv) click to toggle source

This is a bit flakey, but I think it's meaningful.

# File lib/mug/maybe.rb, line 26
def respond_to_missing? meth, priv
  if @o
    @o.repond_to_missing? meth, priv
  else
    true
  end
end