Ruby version annoyances: X.times.inject with LocalJumpError

So, you have fancy spiffy code.  It looks kinda like this:

It works great on your local machine, doing what you need.

Then, you deploy.  And the world ends.  It ends, not in fire, or water, but a LocalJumpError, like so

“WTF?” you think.

Check your Ruby versions.  I bet production is 1.8.6 and your local machine in 1.8.7.  Naughty.

1.8.7 will implicitly do a .to_a right before the inject.  1.8.6 does *not*.

Here’s how to make it work in both:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s