From: itsme213 Date: 2005-04-03T02:34:44+09:00 Subject: Re: how to simulate self-style delegation [SuperHash] "Saynatkari" wrote in message > Perhaps I'm missing a crucial point here. Should a B 'be' an A > in the normal is_a sense? Should B have access to A's state? > Something more than what SimpleDelegator offers? SELF-style delegation is for "inheriting" at the _object_ level. It lets me dynamically change the object that b1 delegates to. b1 = B.new b1.delegate_to(a1) ...stuff b1.delegate_to(a2) So class B < A; end does not help. SimpleDelegator simply forwards missing methods, it does not provide the binding of self that I am looking for. Here is another example with desired behavior at the end. class Role def initialize(type) @type = type end def name "unbound" end def describe "I am #{self.name}, a #{@type}" end end PM = Role.new("Project Manager") GA = Role.new("Graphic Artist") class Person attr_accessor :name def delegate_to ?? method_missing and self_binding magic here end end JOE = Person.new JOE.name = "Joe" JOE.delegate_to(PM) JOE.describe #=> "I am Joe, a Project Manager" JOE.delegate_to(GA) JOE.describe #=> "I am Joe, a Graphic Artist" Hope that is more clear. Maybe this is not possible in Ruby ... but I just got a pointer to _evil_ ruby, perhaps that might have something?