Track object ids so the objects needn't respond to ==

This commit is contained in:
Jeremy Kemper
2009-04-26 15:04:02 -07:00
parent dc2caea9dc
commit da3a80dd4f

View File

@@ -6,8 +6,8 @@ module ActiveSupport
# Converts a Ruby object into a JSON string.
def self.encode(value, options = {})
seen = (options[:seen] ||= [])
raise CircularReferenceError, 'object references itself' if seen.include?(value)
seen << value
raise CircularReferenceError, 'object references itself' if seen.include?(value.object_id)
seen << value.object_id
value.send(:rails_to_json, options)
ensure
seen.pop