class Regexp
def as_json(*)
Regexp.json_create(x) # => /foo/
\Method +JSON.create+ deserializes such a hash, returning a \Regexp object:
# => {"json_class"=>"Regexp", "o"=>0, "s"=>"foo"}
x = /foo/.as_json
require 'json/add/regexp'
returning a 2-element hash representing +self+:
\Method Regexp#as_json serializes +self+,
see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
to serialize and deserialize a \Regexp object;
Methods Regexp#as_json and +Regexp.json_create+ may be used
def as_json(*) { JSON.create_id => self.class.name, 'o' => options, 's' => source, } end