class Rietveld::Role
The Role
class implements a DCI Role
with the Delegator pattern.
It tries to be as transparent as possible to the object it delegates to. For instance most BasicObject and Kernel methods are directly forwarded. Though methods concerning methods and / or instance variables return values from the delegator and the object it delegates to.
Attributes
Returns the context this role is playing in
The object acting out this role
Public Class Methods
# File lib/rietveld/role.rb, line 22 def initialize(role_player, context = nil) self.__role_player__ = role_player self.__context__ = context end
Public Instance Methods
See BasicObject#!, forwarded to role_player
# File lib/rietveld/role.rb, line 103 def ! !__role_player__ end
See BasicObject#!=, forwarded to role_player
# File lib/rietveld/role.rb, line 108 def !=(other) __role_player__ != other end
See Kernel#!~, forwarded to role_player
# File lib/rietveld/role.rb, line 173 def !~(other) __role_player__ !~ other end
See Kernel#<=>, forwarded to role_player
# File lib/rietveld/role.rb, line 188 def <=>(other) __role_player__ <=> other end
See BasicObject#==, forwarded to role_player
# File lib/rietveld/role.rb, line 88 def ==(other) __role_player__ == other end
See Kernel#===, forwarded to role_player
# File lib/rietveld/role.rb, line 163 def ===(other) __role_player__ === other end
See Kernel#=~, forwarded to role_player
# File lib/rietveld/role.rb, line 168 def =~(other) __role_player__ =~ other end
See BasicObject#class, forwarded to role_player
# File lib/rietveld/role.rb, line 98 def class __role_player__.class end
Returns a clone of role object with a clone of the role_player
# File lib/rietveld/role.rb, line 203 def clone role_clone = super role_clone.__role_player__ = __role_player__.clone role_clone end
Returns a dup of role_player
# File lib/rietveld/role.rb, line 210 def dup __role_player__.dup end
See Kernel#eql?, forwarded to role_player
# File lib/rietveld/role.rb, line 178 def eql?(other) __role_player__.eql?(other) end
See BasicObject#equal?, forwarded to role_player
# File lib/rietveld/role.rb, line 93 def equal?(other) __role_player__.equal?(other) end
See Kernel#freeze, forwarded to role_player
# File lib/rietveld/role.rb, line 232 def freeze super __role_player__.freeze end
See Kernel#hash, forwarded to role_player
# File lib/rietveld/role.rb, line 183 def hash __role_player__.hash end
See Kernel#inspect, forwarded to role_player
Returns a string in the form of:
#<ExampleRole:0x37d837e #<ExampleObject>>
# File lib/rietveld/role.rb, line 251 def inspect "#<#{role_class.name}:0x#{__id__.to_s(16)} #{__role_player__.inspect}>" end
See Kernel#instance_of?, forwarded to role_player
# File lib/rietveld/role.rb, line 327 def instance_of?(type) __role_player__.instance_of?(type) end
See Kernel#instance_variable_defined?, returns true if an instance variable is defined on either role_player or the role object
# File lib/rietveld/role.rb, line 311 def instance_variable_defined?(name) super || __role_player__.instance_variable_defined?(name) end
See Kernel#instance_variable_get, prefers to return an instance variable defined on role_player, otherwise will lookup instance variables on role
# File lib/rietveld/role.rb, line 294 def instance_variable_get(name) __role_player__.instance_variable_get(name) || super end
See Kernel#instance_variable_set, prefers to set an instance variable on role_player, if an instance variable with the same name on the role object is already set, it wil set one on the role.
# File lib/rietveld/role.rb, line 301 def instance_variable_set(name, value) if role_instance_variable_defined?(name) super else __role_player__.instance_variable_set(name, value) end end
See Kernel#instance_variables, returns the union of the instance_variables
from the role object and role_player
# File lib/rietveld/role.rb, line 287 def instance_variables super | __role_player__.instance_variables end
See Kernel#is_a?, forwarded to role_player
# File lib/rietveld/role.rb, line 337 def is_a?(type) __role_player__.is_a?(type) end
See Kernel#kind_of?, forwarded to role_player
# File lib/rietveld/role.rb, line 332 def kind_of?(type) __role_player__.kind_of?(type) end
See Kernel#method, if given method is defined on role object, it will return that one, otherwise the one from role_player
# File lib/rietveld/role.rb, line 343 def method(name) super rescue __role_player__.method(name) end
See Kernel#methods, returns the union of the methods from the role object and role_player
# File lib/rietveld/role.rb, line 257 def methods super | __role_player__.methods end
See Kernel#nil?, forwarded to role_player
# File lib/rietveld/role.rb, line 158 def nil? __role_player__.nil? end
See Kernel#private_methods, returns the union of the private_methods
from the role object and role_player
# File lib/rietveld/role.rb, line 275 def private_methods super | __role_player__.private_methods end
See Kernel#protected_methods, returns the union of the protected_methods
from the role object and role_player
# File lib/rietveld/role.rb, line 269 def protected_methods super | __role_player__.protected_methods end
See Kernel#public_method, if given public_method
is defined on role object, it will return that one, otherwise the one from role_player
# File lib/rietveld/role.rb, line 351 def public_method(name) super rescue __role_player__.public_method(name) end
See Kernel#private_methods, returns the union of the private_methods
from the role object and role_player
# File lib/rietveld/role.rb, line 281 def public_methods super | __role_player__.public_methods end
See Kernel#remove_instance_variable, if the instance variable is defined on the role object, it wil remove that one, else it will remove one defined on role_player
# File lib/rietveld/role.rb, line 318 def remove_instance_variable(name) if role_instance_variable_defined?(name) super else __role_player__.remove_instance_variable(name) end end
Remove an instance variable defined on the role
True if either role object or role_player responds to given method
# File lib/rietveld/role.rb, line 144 def respond_to?(name, include_all = false) __role_player__.respond_to?(name, include_all) || super end
True if either role object or role_player responds to given missing method
# File lib/rietveld/role.rb, line 149 def respond_to_missing?(name, include_private = false) __role_player__.respond_to_missing?(name, include_private) || super end
Is given instance variable defined on the role
Get an instance variable defined on the role
Set an instance variable defined on the role
Gets the instance variables defined on the role itself
Get an array of private methods defined on the role itself
Get an array of protected methods defined on the role itself
Get an array of public methods defined on the role itself
Gets a singleton method defined on the role itself
Gets the singleton methods defined on the role itself
Returns the singleton_class
of the role_player
# File lib/rietveld/role.rb, line 198 def singleton_class __role_player__.singleton_class end
See Kernel#singleton_method, if given singleton_method
is defined on role object, it will return that one, otherwise the one from role_player
# File lib/rietveld/role.rb, line 359 def singleton_method(name) super rescue __role_player__.singleton_method(name) end
See Kernel#singleton_methods, returns the union of the singleton methods from the role object and role_player
# File lib/rietveld/role.rb, line 263 def singleton_methods __role_player__.singleton_methods end
See Kernel#taint, forwarded to role_player
# File lib/rietveld/role.rb, line 215 def taint super __role_player__.taint end
See Kernel#tainted?, forwarded to role_player
# File lib/rietveld/role.rb, line 221 def tainted? super || __role_player__.tainted? end
See Kernel#to_s, forwarded to role_player
# File lib/rietveld/role.rb, line 243 def to_s __role_player__.to_s end
See Kernel#unfreeze, forwarded to role_player
# File lib/rietveld/role.rb, line 238 def unfreeze super || __role_player__.frozen? end
See Kernel#untaint, forwarded to role_player
# File lib/rietveld/role.rb, line 226 def untaint super __role_player__.untaint end
Returns the role_player without its role object wrapping it.
# File lib/rietveld/role.rb, line 28 def unwrap __role_player__ end
Private Instance Methods
If the role itself does not have a given method defined, it will try to delegate it to the role_player
# File lib/rietveld/role.rb, line 131 def method_missing(name, *args, &block) if __role_player__.respond_to?(name) __role_player__.__send__(name, *args, &block) elsif __context__.role?(name) __context__.send(name) else super end end
See BasicObject#singleton_method_added, forwarded to role_player
# File lib/rietveld/role.rb, line 115 def singleton_method_added(sym) __role_player__.singleton_method_added(sym) end
See BasicObject#singleton_method_removed, forwarded to role_player
# File lib/rietveld/role.rb, line 120 def singleton_method_removed(sym) __role_player__.singleton_method_removed(sym) end
See BasicObject#singleton_method_undefined, forwarded to role_player
# File lib/rietveld/role.rb, line 125 def singleton_method_undefined(sym) __role_player__.singleton_method_undefined(sym) end