Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/extensions/string.rb
Class Method Summary collapse
-
.json_create(o) ⇒ Object
Raw Strings are JSON Objects (the raw bytes are stored in an array for the key “raw”).
Instance Method Summary collapse
-
#to_json_raw(*args) ⇒ Object
This method should be used, if you want to convert raw strings to JSON instead of UTF-8 strings, e.
-
#to_json_raw_object ⇒ Object
This method creates a raw object, that can be nested into other data structures and will be unparsed as a raw string.
Class Method Details
.json_create(o) ⇒ Object
Raw Strings are JSON Objects (the raw bytes are stored in an array for the key “raw”). The Ruby String can be created by this class method.
4 5 6 |
# File 'lib/extensions/string.rb', line 4 def self.json_create(o) o['raw'].pack('C*') end |
Instance Method Details
#to_json_raw(*args) ⇒ Object
This method should be used, if you want to convert raw strings to JSON instead of UTF-8 strings, e. g. binary data (and JSON Unicode support is enabled).
20 21 22 |
# File 'lib/extensions/string.rb', line 20 def to_json_raw(*args) to_json_raw_object.to_json(*args) end |
#to_json_raw_object ⇒ Object
This method creates a raw object, that can be nested into other data structures and will be unparsed as a raw string.
10 11 12 13 14 15 |
# File 'lib/extensions/string.rb', line 10 def to_json_raw_object { 'json_class' => self.class.name, 'raw' => self.unpack('C*'), } end |