From: Joel VanderWerf Date: 2010-09-16T05:45:13+09:00 Subject: Re: access super from yield block? On 09/15/2010 01:12 PM, Gene Angelo wrote: >> What exactly are trying to achieve? > > I have class A that derives from class B > > A#parse and A#parse! override members of the same name in B > > A#parse and A#parse! both call A#do_parse to retrieve arguments from the > command line in a loop. A yield in A#do_parse returns the arguments > (argv). I want to call 'super argv' from both A#parse and A#parse! but > super is not set to A#super. > > # simplified... > class A< B > ... > > def parse > do_parse {|a| super a} > end > > def parse! > do_parse {|a| super a} > def > > def do_parse > argv = gets.strip.to_a > return ['-x'] if argv.index '-x' > return ['-h'] if argv.empty? > yield argv > end > protected :do_parse > > ... > end That should work. Can you isolate the problem in a small piece of code you can post here? Here's a working example: class A def foo a "A#foo: #{a}" end end class B < A def do_something yield 3 end def foo s = do_something {|a| super a} "B#foo: " + s end end p B.new.foo # ==> "B#foo: A#foo: 3"