Q: Delegate and Forwardable

B

benny

hi,

I am playing around with Delegate and Forwardable,

In the code below, I thought in the run method of class A it should be
possible to set prob_b2 by simply calling

prop_b2 = "something"

as you can see the delegation 'back' works if I want to get the content of
prop_b1.

BTW the same thing when defining an explicit setter method for prob_b2.

any pointers?

benny

##### the code

require 'delegate'
require 'forwardable'

class A
extend Forwardable
def run()
puts "here runs A, giving you property b1: '#{prop_b1}'"
prop_b2 = "new value of b2"
puts @b.prop_b2
@b.prop_b2 = "2nd try: new value of b2"
puts @b.prop_b2
end

def initialize(b)
@b = b
end

def_delegators:)@b, :prop_b1, :prop_b2, :prop_b2=)
end

class B < DelegateClass(A)
attr_accessor :prop_b1, :prop_b2

def initialize(prop_b1)
@prop_b1 = prop_b1
super( A.new(self) )
end
end

b = B.new( "my property b1 content")
b.run

##### output
here runs A, giving you property b1: 'my property b1 content'
nil
2nd try: new value of b2

--
---------------------------------------------------------------------------------------------------
Don't crash when a filter changes the subject of a message which results
in the attempt to remove it from the tree of subject threading messages
failing and the detached child looking for a new parent finding the old
parent as the new parent, which in turn results in the child being deleted
with the old (and new) parent, which is not a good idea, since it is
still referenced.

(Till Adams commit on kdepim/kmail/kmheaders.cpp in HEAD, 6. Jan. 2005)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top