module Surrounded
This module should be added to objects which will enter into context objects.
Its main purpose is to keep a reference to the context and to implement method_missing
to handle the relationship to other objects in the context.
Extend your classes with Surrounded::Context
to handle their initialization and application of behaviors to the role players passed into the constructor.
The purpose of this module is to help you create context objects which encapsulate the interaction and behavior of objects inside.
Constants
- VERSION
Public Class Methods
version()
click to toggle source
# File lib/surrounded/version.rb, line 4 def self.version VERSION end
Private Instance Methods
context()
click to toggle source
# File lib/surrounded.rb, line 31 def context surroundings.first || NullContext.instance end
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
# File lib/surrounded.rb, line 35 def method_missing(meth, *args, &block) context.role?(meth){} || super end
remove_context(&block)
click to toggle source
# File lib/surrounded.rb, line 21 def remove_context(&block) accessor = block.binding.eval('self') surroundings.shift if surroundings.include?(accessor) self end
respond_to_missing?(meth, include_private=false)
click to toggle source
Calls superclass method
# File lib/surrounded.rb, line 39 def respond_to_missing?(meth, include_private=false) !!context.role?(meth){} || super end
store_context(&block)
click to toggle source
# File lib/surrounded.rb, line 15 def store_context(&block) accessor = block.binding.eval('self') surroundings.unshift(accessor) self end
surroundings()
click to toggle source
# File lib/surrounded.rb, line 27 def surroundings @__surroundings__ ||= [] end