Class: Fuby::Try::Base

Inherits:
BasicObject
Defined in:
lib/fuby/try.rb

Direct Known Subclasses

Each, Many, Once

Instance Method Summary collapse

Constructor Details

#initialize(object, maybe = nil) ⇒ Base

Returns a new instance of Base.



37
38
39
40
41
# File 'lib/fuby/try.rb', line 37

def initialize object, maybe = nil
  @object = object
  @maybe  = maybe
  @class  = (class << self; self end).superclass
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *sig, &blk) ⇒ Object



43
44
45
46
# File 'lib/fuby/try.rb', line 43

def method_missing key, *sig, &blk
  return __wrap__ @object.send key, *sig, &blk if @object.respond_to? key
  return __wrap__ nil
end

Instance Method Details

#__unwrap__Object



48
49
50
# File 'lib/fuby/try.rb', line 48

def __unwrap__
  @object.nil? ? @maybe : @object
end

#__wrap__(result) ⇒ Object



52
53
54
# File 'lib/fuby/try.rb', line 52

def __wrap__ result
  @class.new result, @maybe
end