In general, I'm a fan of monkey patching. It usually makes writing and reading code easier. However, there are times when it breaks down. This is one of those times.
If you require the json gem first, and then require active_support, you can't convert some simple data structures to json.
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'json'
=> true
irb(main):003:0> require 'active_support'
=> true
irb(main):004:0> {:a => []}.to_json
TypeError: wrong argument type Hash (expected Data)
If you require the active_support gem first, and then require json, you can convert the data structures.
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'active_support'
r=> true
irb(main):003:0> require 'json'
=> []
irb(main):004:0> {:a => []}.to_json
=> "{\"a\":[]}"
You can also convert the data structure to JSON if you use either of the gems individually. However, with multiple dependencies in different modules, sometimes that's hard to do.
Comments