Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Why doesn't this code work?

animals = %w(narwhal octopus wallaby worm)

for animal in animals
    puts "The current animal is #{animal}"
    retry if animal == 'octopus'
end

I can't see anything wrong with it, yet the retry line produces an error....?!

Ah, it's because the video is out of date. In the current Ruby (around 1.9.3 now), you can't use retry like this. I'm moving on to the next video.

Would be nice to have this updated!

1 Answer

Just to get this out of the unanswered section, this is true 'retry' can't be used outside of a rescue block.

But you can use 'redo' if you want the same functionality. That's what I've read anyway. I haven't really tested it out myself. Might make a good experiment for you.