tags:

views:

82

answers:

1

What is the proper way in ruby to call a method from within itself to rerun In the sample below when @dest_reenter is equal to yes I would want the b_stage method to execute again

def b_stage 
    if @dest_reenter == 'yes'
        @dest_reenter = nil
        b_stage
    end
end
+2  A: 

That is how you do recursion, but using those instance variables isn't the way to go. A better example would be something like this:

def b_stage(i)
    if i < 5
        puts i
        i += 1
        b_stage(i)
    end
end

If you call b_stage(0), the output will be

0
1
2
3
4
Jesse J