Module: Fidgit::RedirectorMethods

Included in:
Object
Defined in:
lib/fidgit/redirector.rb

Overview

Redirects methods to an object, but does not mask methods and ivars from the calling context.

Instance Method Summary (collapse)

Instance Method Details

- (Object) instance_methods_eval(&block)

Evaluate a block accessing methods and ivars from the calling context, but calling public methods (not ivars or non-public methods) on this object in preference.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fidgit/redirector.rb', line 6

def instance_methods_eval(&block)
  raise ArgumentError, "block required" unless block_given?

  context = eval('self', block.binding)

  context.send :push_redirection_target, self

  begin
    yield context
  ensure
    context.send :pop_redirection_target
  end

  self
end