rails/rails — pull request #12203 by chancancode (2013-09-12 02:25:00+00:00)
Title: Eagerload active_support/json/encoding in active_support/core_ext/object/to_json 

This is related to #12106. (The root cause for that ticket is that
json/add defines Regexp#to_json among others, but here I'll reproduce
the problem without json/add.)

Before:

>> require 'active_support/core_ext'
=> true
>> //.as_json
NoMethodError: undefined method `as_json' for //:Regexp
from (irb):3
from /Users/godfrey/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `

'
>> //.to_json
=> "\"(?-mix:)\""
>> //.as_json
=> "(?-mix:)"

After:

>> require 'active_support/core_ext'
=> true
>> //.as_json
=> "(?-mix:)"

When someone require 'active_support/core_ext', the expectation is
that it would add certain methods to the core classes NOW. The
previous behaviour causes additional methods to be loaded the first
time you call `to_json`, which could cause nasty surprises.