J
Jesse Merriman
I'm trying to use SimpleDelegator, but am having a problem overring a method.
Here's a boiled-down version:
$ cat delegator_test.rb
#!/usr/bin/env ruby
require 'delegate'
class A
def foo
bar()
#self.bar()
end
def bar
'original'
end
end
class B < SimpleDelegator
def initialize
super A.new
end
def bar
'overridden'
end
end
puts B.new.foo
$ ./delegator_test.rb
original
I wanted "overridden" to be output. Is there a good way to do this? Since I'm
changing the delegated object with __setobj__, subclassing won't work, and I'd
rather not have to override all methods that call overridden methods. Note that
this works:
Here's a boiled-down version:
$ cat delegator_test.rb
#!/usr/bin/env ruby
require 'delegate'
class A
def foo
bar()
#self.bar()
end
def bar
'original'
end
end
class B < SimpleDelegator
def initialize
super A.new
end
def bar
'overridden'
end
end
puts B.new.foo
$ ./delegator_test.rb
original
I wanted "overridden" to be output. Is there a good way to do this? Since I'm
changing the delegated object with __setobj__, subclassing won't work, and I'd
rather not have to override all methods that call overridden methods. Note that
this works:
overriddenputs B.new.bar