Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

#as_json returning self?

#4380

I may have completely misunderstood what the #as_json method is for, but it was my assumption that it's supposed to return a JSON-mappable version of the object.

Meaning, it should return a String, Fixnum, TrueClass, FalseClass, NilClass, Array or Hash. In literally every example of it's use those are the types that are returned - which makes perfect sense.

But classes like Regexp and BigDecimal return self? If a JSON library checks to see if the object responds to #as_json, and calls it if so, it'll infinitely loop.

Should BigDecimal return to_f? And Regexp to_s?

Reported by Brian Lopez · April 12th, 2010 @ 10:57 PM

State: duplicate
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to duplicate

    Duplicates #4375

    April 12th, 2010 @ 11:17 PM