John John - 2 months ago 5x
Ruby Question

Rails 3.2.21 and Ruby 2.2.0 breaking

With Rails 3.2.21 and Ruby 2.2.0p0 the time zone parser is broken. With Ruby 2.1.2 this was working just fine.

[1] pry(main)>"2015-01-12")
NoMethodError: undefined method `year' for nil:NilClass
from /Users/user/.rvm/gems/ruby-2.2.0/gems/activesupport-3.2.21/lib/active_support/values/time_zone.rb:275:in `parse'

Now I know that you can replace it with
but this breaks functionality in my apps. Are there any known fixes for this?


TLDR: rails bug that has been fixed, first fixed version on the 3.2 branch is 3.2.22

Ruby 2.2 changes how default arguments are resolved when there is a name ambiguity:

def now

def foo(now = now)

In older versions of ruby calling foo with no arguments results in the argument now Being set to whatever the now() method calls. In ruby 2.2 it would instead be set to nil (and you get a warning about a circular reference)

You can resolve the ambiguity by doing either

def foo(now = now())


def foo(something = now)

(And obviously changing uses of that argument)

Apparently the way it used to work was a bug all along. Rails had a few places where this bad behaviour was relied on, including in AS::Timezone.parse. The fix was backported to the 3-2-stable branch and eventually released as part of 3.2.22.

The commit to rails master fixing the issue has a link to the ruby bug filed about this