Conveniently turn a string into a tuple.
[ show source ]
# File lib/facets/more/typecast.rb, line 154 def cast_from(object, options={}) retval = super return retval unless retval == nil return object.to_s if object.respond_to? :to_s end
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.
[ show source ]
# File lib/facets/more/json.rb, line 605 def self.json_create(o) o['raw'].pack('C*') end
[ show source ]
# File lib/facets/more/snapshot.rb, line 145 def restore_snapshot(snap) replace(snap) end
[ show source ]
# File lib/facets/more/snapshot.rb, line 144 def take_snapshot() dup end
This string should be encoded with UTF-8 (if JSON unicode support is enabled). A call to this method returns a JSON string encoded with UTF16 big endian characters as \u????. If JSON.support_unicode? is false only control characters are encoded this way, all 8-bit bytes are just passed through.
[ show source ]
# File lib/facets/more/json.rb, line 599 def to_json(*) '"' << JSON::utf8_to_json(self) << '"' end
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).
[ show source ]
# File lib/facets/more/json.rb, line 621 def to_json_raw(*args) to_json_raw_object.to_json(*args) end
This method creates a raw object, that can be nested into other data structures and will be unparsed as a raw string.
[ show source ]
# File lib/facets/more/json.rb, line 611 def to_json_raw_object { 'json_class' => self.class.name, 'raw' => self.unpack('C*'), } end
[ show source ]
# File lib/facets/more/tuple.rb, line 249 def to_t( &yld ) Tuple.cast_from_string( self, &yld ) end