G
Gene Angelo
Is there a way to access super from a yield block?
Is there a way to access super from a yield block?
Is there a way to access super from a yield block?
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.
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
Gene said: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.
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
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.