class Range
def as_json(*)
Range.json_create(z) # => "a".."d"
Range.json_create(y) # => 1...4
Range.json_create(x) # => 1..4
\Method +JSON.create+ deserializes such a hash, returning a \Range object:
z = ('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
y = (1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
x = (1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
require 'json/add/range'
returning a 2-element hash representing +self+:
\Method Range#as_json serializes +self+,
see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
to serialize and deserialize a \Range object;
Methods Range#as_json and +Range.json_create+ may be used
def as_json(*) { JSON.create_id => self.class.name, 'a' => [ first, last, exclude_end? ] } end