Class: String
Class Method Summary collapse
Instance Method Summary collapse
-
#to_json ⇒ Object
produce a string in double quotes with all the necessary quoting done.
Class Method Details
.to_json(str) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# 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 |
Instance Method Details
#to_json ⇒ Object
produce a string in double quotes with all the necessary quoting done
61 62 63 |
# File 'lib/json/objects.rb', line 61 def to_json return String.to_json(self) end |