Class: Trying::Proxy
- Inherits:
-
BasicObject
- Defined in:
- lib/trying.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(obj) ⇒ Proxy
Returns a new instance of Proxy.
5
6
7
|
# File 'lib/trying.rb', line 5
def initialize(obj)
@cell = obj
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *argv, &block) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/trying.rb', line 9
def method_missing(method, *argv, &block)
return nil unless @cell.respond_to?(method)
@cell = @cell.instance_eval do
public_send(method, *argv, &block)
end
end
|
Instance Attribute Details
#cell ⇒ Object
Returns the value of attribute cell.
3
4
5
|
# File 'lib/trying.rb', line 3
def cell
@cell
end
|
Instance Method Details
#failed?(error = ::StandardError, &block) ⇒ Boolean
31
32
33
|
# File 'lib/trying.rb', line 31
def failed?(error = ::StandardError, &block)
with(&block) if @cell.is_a? error
end
|
#pipe(method, *argv, &block) ⇒ Object
27
28
29
|
# File 'lib/trying.rb', line 27
def pipe(method, *argv, &block)
method.call(@cell, *argv, &block)
end
|
#tap(&block) ⇒ Object
21
22
23
24
25
|
# File 'lib/trying.rb', line 21
def tap(&block)
block.call(@cell)
rescue => e
@cell = e
end
|
#with(&block) ⇒ Object
17
18
19
|
# File 'lib/trying.rb', line 17
def with(&block)
@cell = tap(&block)
end
|