Class: Proc

Inherits:
Object show all
Defined in:
lib/mixico.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) __context__

The context of the block

Returns:

  • (Object)

    The value of self inside the block



25
26
27
# File 'lib/mixico.rb', line 25

def __context__
  eval('self', binding)
end

- (Boolean) includes_mixin?(mod)

indicates whether the module mod is currently mixed in to the receiver

Parameters:

  • mod (Module)

    The module to check for inclusion

Returns:

  • (Boolean)

    True if the module is included, false if not



32
33
34
# File 'lib/mixico.rb', line 32

def includes_mixin? mod
  (class << __context__; self end).include? mod
end

- (Object) mixin(mod)

Mixes a module into the context of the Proc

Examples:

def hello(&block)
  block.mixin MyModule
end

Parameters:

  • mod (Module)

    The module to mix in



42
43
44
# File 'lib/mixico.rb', line 42

def mixin mod 
  __context__.extend mod
end

- (Object) mixout(mod)

Removes a module from the context of the Proc

Examples:

def hello(&block)
  block.mixin MyModule
  block.mixout MyModule
end

Parameters:

  • mod (Module)

    The module to remove from the Proc context.



53
54
55
# File 'lib/mixico.rb', line 53

def mixout mod
  (class << __context__; self end).disable_mixin mod
end