When to use DelegateClass instead of SimpleDelegator?

I am mostly re-posting my question from SO, because i think it can get
lost there, and i hope that on this specialized forum i would get some
explanation.

So, i do not understand how and when to use Ruby’s DelegateClass
method instead of SimpleDelegator class. All of the following seem to
work mostly identically:

a = SimpleDelegator.new([0])
b = DelegateClass(Array).new([0])
c = DelegateClass(String).new([0])
a << 1
b << 2
c << 3
p a # => [0, 1]
p b # => [0, 2]
p c # => [0, 3]

It does not seem to matter which class is passed to DelegateClass.

Alexey.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs