Created
April 29, 2009 18:04
-
-
Save brianmario/103929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Yajl | |
module Stream | |
def self.encode(obj) | |
case obj.class.name | |
when "Hash" | |
val = "{" | |
val << obj.keys.map do |key| | |
"\"#{key}\": #{encode(obj[key])}" | |
end * ", " | |
val << "}" | |
when "Array" | |
"[#{obj.map{|val| encode(val)} * ', '}]" | |
when "NilClass" | |
"null" | |
when "TrueClass", "FalseClass", "Fixnum", "Float" | |
obj.to_s | |
else | |
"\"#{obj.to_s}\"" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment