class String
Public Class Methods
to_json(str)
click to toggle source
# File lib/json/objects.rb, line 65 def self.to_json(str) return "\"\"" if (str.length == 0) newstr = "\"" str.each_byte { |b| c = b.chr case c when /\\|\"|\// newstr << "\\" + c when "\b" newstr << "\\b" when "\t" newstr << "\\t" when "\n" newstr << "\\n" when "\f" newstr << "\\f" when "\r" newstr << "\\r" else if (c < ' ') t = "000" + sprintf("%0x", b) newstr << ("\\u" + t[0,t.length - 4]) else newstr << c end end } newstr += '"' return(newstr) end
Public Instance Methods
to_json()
click to toggle source
produce a string in double quotes with all the necessary quoting done
# File lib/json/objects.rb, line 61 def to_json return String.to_json(self) end