Skip to content

Instantly share code, notes, and snippets.

@jsperezg
Created April 20, 2017 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsperezg/fbd811230b1aabefab5231efe173119c to your computer and use it in GitHub Desktop.
Save jsperezg/fbd811230b1aabefab5231efe173119c to your computer and use it in GitHub Desktop.
Serializes numbers with more than 53 bit as strings.
class Fixnum
alias_method :default_as_json, :as_json
# Serializes long integers as strings.
def as_json(options = {})
if self.bit_length > 53
"#{ default_as_json(options) }"
else
default_as_json(options)
end
end
def to_json(options = {})
as_json(options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment