Class: Wormhole

Inherits:
Object
  • Object
show all
Defined in:
lib/wormhole.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.catch(&block) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/wormhole.rb', line 2

def self.catch(&block)
  result = nil
  wormhole = Kernel.catch(:__wormhole__) do
    result = block.call if block
    nil
  end || new
  wormhole.instance_variable_set(:@result, result)
  wormhole
end

.throw(data = {}, &block) ⇒ Object



12
13
14
# File 'lib/wormhole.rb', line 12

def self.throw(data = {}, &block)
  new.send :connect, data, &block
end

Instance Method Details

#return(&block) ⇒ Object

returns the result of the catch block.



17
18
19
20
21
22
# File 'lib/wormhole.rb', line 17

def return(&block)
  return @result if @cc.nil?
  block.call @data if block
  @opened = true
  @cc.call
end