Module: Affect

Extended by:
Affect
Included in:
Affect
Defined in:
lib/affect.rb,
lib/affect/cont.rb,
lib/affect/fiber.rb,
lib/affect/version.rb

Overview

Affect module

Defined Under Namespace

Modules: Cont, Fiber Classes: Context

Constant Summary collapse

VERSION =
'0.4'

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



95
96
97
# File 'lib/affect.rb', line 95

def method_missing(*args, &block)
  perform(*args, &block)
end

Instance Method Details

#block_and_handlers_from_args(*args, &block) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/affect.rb', line 67

def block_and_handlers_from_args(*args, &block)
  case args.size
  when 1 then block ? [block, args.first] : [args.first, nil]
  when 2 then args
  else [block, nil]
  end
end

#capture(*args, &block) ⇒ Object



61
62
63
64
65
# File 'lib/affect.rb', line 61

def capture(*args, &block)
  block, handlers = block_and_handlers_from_args(*args, &block)
  handlers = { nil => handlers } if handlers.is_a?(Proc)
  Context.new(handlers).capture(&block)
end

#escape(value = nil, &block) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/affect.rb', line 83

def escape(value = nil, &block)
  unless (ctx = Context.current)
    raise 'escape called outside capture block'
  end

  ctx.escape(value, &block)
end

#perform(effect, *args, &block) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/affect.rb', line 75

def perform(effect, *args, &block)
  unless (ctx = Context.current)
    raise 'perform called outside capture block'
  end

  ctx.perform(effect, *args, &block)
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/affect.rb', line 91

def respond_to_missing?(*)
  true
end