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

__context__[RW]

Returns the context this role is playing in

__role_player__[RW]

The object acting out this role

Public Class Methods

new(role_player, context = nil) click to toggle source
# 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

!() click to toggle source

See BasicObject#!, forwarded to role_player

# File lib/rietveld/role.rb, line 103
def !
  !__role_player__
end
!=(other) click to toggle source

See BasicObject#!=, forwarded to role_player

# File lib/rietveld/role.rb, line 108
def !=(other)
  __role_player__ != other
end
!~(other) click to toggle source

See Kernel#!~, forwarded to role_player

# File lib/rietveld/role.rb, line 173
def !~(other)
  __role_player__ !~ other
end
<=>(other) click to toggle source

See Kernel#<=>, forwarded to role_player

# File lib/rietveld/role.rb, line 188
def <=>(other)
  __role_player__ <=> other
end
==(other) click to toggle source

See BasicObject#==, forwarded to role_player

# File lib/rietveld/role.rb, line 88
def ==(other)
  __role_player__ == other
end
===(other) click to toggle source

See Kernel#===, forwarded to role_player

# File lib/rietveld/role.rb, line 163
def ===(other)
  __role_player__ === other
end
=~(other) click to toggle source

See Kernel#=~, forwarded to role_player

# File lib/rietveld/role.rb, line 168
def =~(other)
  __role_player__ =~ other
end
class() click to toggle source

See BasicObject#class, forwarded to role_player

# File lib/rietveld/role.rb, line 98
def class
  __role_player__.class
end
Also aliased as: role_class
clone() click to toggle source

Returns a clone of role object with a clone of the role_player

Calls superclass method
# File lib/rietveld/role.rb, line 203
def clone
  role_clone = super
  role_clone.__role_player__ = __role_player__.clone
  role_clone
end
dup() click to toggle source

Returns a dup of role_player

# File lib/rietveld/role.rb, line 210
def dup
  __role_player__.dup
end
eql?(other) click to toggle source

See Kernel#eql?, forwarded to role_player

# File lib/rietveld/role.rb, line 178
def eql?(other)
  __role_player__.eql?(other)
end
Also aliased as: role_eql?
equal?(other) click to toggle source

See BasicObject#equal?, forwarded to role_player

# File lib/rietveld/role.rb, line 93
def equal?(other)
  __role_player__.equal?(other)
end
Also aliased as: role_equal?
freeze() click to toggle source

See Kernel#freeze, forwarded to role_player

Calls superclass method
# File lib/rietveld/role.rb, line 232
def freeze
  super
  __role_player__.freeze
end
hash() click to toggle source

See Kernel#hash, forwarded to role_player

# File lib/rietveld/role.rb, line 183
def hash
  __role_player__.hash
end
Also aliased as: role_hash
inspect() click to toggle source

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
instance_of?(type) click to toggle source

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
instance_variable_defined?(name) click to toggle source

See Kernel#instance_variable_defined?, returns true if an instance variable is defined on either role_player or the role object

Calls superclass method
# File lib/rietveld/role.rb, line 311
def instance_variable_defined?(name)
  super || __role_player__.instance_variable_defined?(name)
end
instance_variable_get(name) click to toggle source

See Kernel#instance_variable_get, prefers to return an instance variable defined on role_player, otherwise will lookup instance variables on role

Calls superclass method
# File lib/rietveld/role.rb, line 294
def instance_variable_get(name)
   __role_player__.instance_variable_get(name) || super
end
Also aliased as: role_instance_variable_get
instance_variable_set(name, value) click to toggle source

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.

Calls superclass method
# 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
Also aliased as: role_instance_variable_set
instance_variables() click to toggle source

See Kernel#instance_variables, returns the union of the instance_variables from the role object and role_player

Calls superclass method
# File lib/rietveld/role.rb, line 287
def instance_variables
  super | __role_player__.instance_variables
end
Also aliased as: role_instance_variables
is_a?(type) click to toggle source

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
kind_of?(type) click to toggle source

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
method(name) click to toggle source

See Kernel#method, if given method is defined on role object, it will return that one, otherwise the one from role_player

Calls superclass method
# File lib/rietveld/role.rb, line 343
def method(name)
  super
rescue
  __role_player__.method(name)
end
Also aliased as: role_method
methods() click to toggle source

See Kernel#methods, returns the union of the methods from the role object and role_player

Calls superclass method
# File lib/rietveld/role.rb, line 257
def methods
  super | __role_player__.methods
end
Also aliased as: role_methods
nil?() click to toggle source

See Kernel#nil?, forwarded to role_player

# File lib/rietveld/role.rb, line 158
def nil?
  __role_player__.nil?
end
private_methods() click to toggle source

See Kernel#private_methods, returns the union of the private_methods from the role object and role_player

Calls superclass method
# File lib/rietveld/role.rb, line 275
def private_methods
  super | __role_player__.private_methods
end
Also aliased as: role_private_methods
protected_methods() click to toggle source

See Kernel#protected_methods, returns the union of the protected_methods from the role object and role_player

Calls superclass method
# File lib/rietveld/role.rb, line 269
def protected_methods
  super | __role_player__.protected_methods
end
Also aliased as: role_protected_methods
public_method(name) click to toggle source

See Kernel#public_method, if given public_method is defined on role object, it will return that one, otherwise the one from role_player

Calls superclass method
# File lib/rietveld/role.rb, line 351
def public_method(name)
  super
rescue
  __role_player__.public_method(name)
end
public_methods() click to toggle source

See Kernel#private_methods, returns the union of the private_methods from the role object and role_player

Calls superclass method
# File lib/rietveld/role.rb, line 281
def public_methods
  super | __role_player__.public_methods
end
Also aliased as: role_public_methods
remove_instance_variable(name) click to toggle source

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

Calls superclass method
# 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_role_instance_variable(name)

Remove an instance variable defined on the role

respond_to?(name, include_all = false) click to toggle source

True if either role object or role_player responds to given method

Calls superclass method
# File lib/rietveld/role.rb, line 144
def respond_to?(name, include_all = false)
  __role_player__.respond_to?(name, include_all) || super
end
respond_to_missing?(name, include_private = false) click to toggle source

True if either role object or role_player responds to given missing method

Calls superclass 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
role_class()

Returns the class of the role itself

Alias for: class
role_eql?(other)

Is the other role eql? to this one

Alias for: eql?
role_equal?(other)

Is the other role equal? to this one

Alias for: equal?
role_hash()

Get the hash for the role

Alias for: hash
role_instance_variable_defined?(name)

Is given instance variable defined on the role

role_instance_variable_get(name)

Get an instance variable defined on the role

role_instance_variable_set(name, value)

Set an instance variable defined on the role

role_instance_variables()

Gets the instance variables defined on the role itself

Alias for: instance_variables
role_method(name)

Gets a method defined on the role itself

Alias for: method
role_methods()

Get an array of methods defined on the role itself

Alias for: methods
role_private_methods()

Get an array of private methods defined on the role itself

Alias for: private_methods
role_protected_methods()

Get an array of protected methods defined on the role itself

Alias for: protected_methods
role_public_methods()

Get an array of public methods defined on the role itself

Alias for: public_methods
role_singleton_class()

Get the singleton class of the role

Alias for: singleton_class
role_singleton_method(name)

Gets a singleton method defined on the role itself

Alias for: singleton_method
role_singleton_methods()

Gets the singleton methods defined on the role itself

Alias for: singleton_methods
singleton_class() click to toggle source

Returns the singleton_class of the role_player

# File lib/rietveld/role.rb, line 198
def singleton_class
  __role_player__.singleton_class
end
Also aliased as: role_singleton_class
singleton_method(name) click to toggle source

See Kernel#singleton_method, if given singleton_method is defined on role object, it will return that one, otherwise the one from role_player

Calls superclass method
# File lib/rietveld/role.rb, line 359
def singleton_method(name)
  super
rescue
  __role_player__.singleton_method(name)
end
Also aliased as: role_singleton_method
singleton_methods() click to toggle source

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
Also aliased as: role_singleton_methods
taint() click to toggle source

See Kernel#taint, forwarded to role_player

Calls superclass method
# File lib/rietveld/role.rb, line 215
def taint
  super
  __role_player__.taint
end
tainted?() click to toggle source

See Kernel#tainted?, forwarded to role_player

Calls superclass method
# File lib/rietveld/role.rb, line 221
def tainted?
  super || __role_player__.tainted?
end
to_s() click to toggle source

See Kernel#to_s, forwarded to role_player

# File lib/rietveld/role.rb, line 243
def to_s
  __role_player__.to_s
end
unfreeze() click to toggle source

See Kernel#unfreeze, forwarded to role_player

Calls superclass method
# File lib/rietveld/role.rb, line 238
def unfreeze
  super || __role_player__.frozen?
end
untaint() click to toggle source

See Kernel#untaint, forwarded to role_player

Calls superclass method
# File lib/rietveld/role.rb, line 226
def untaint
  super
  __role_player__.untaint
end
unwrap() click to toggle source

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

method_missing(name, *args, &block) click to toggle source

If the role itself does not have a given method defined, it will try to delegate it to the role_player

Calls superclass method
# 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
singleton_method_added(sym) click to toggle source

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
singleton_method_removed(sym) click to toggle source

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
singleton_method_undefined(sym) click to toggle source

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