123456789_123456789_123456789_123456789_123456789_

Class: Range

Relationships & Source Files
Inherits: Object
Defined in: ext/json/lib/json/add/range.rb

Class Method Summary

Instance Method Summary

  • #as_json

    Returns a hash, that will be turned into a ::JSON object and represent this object.

  • #to_json(*args)

    Stores class name (Range) with ::JSON array of arguments a which include first (integer), last (integer), and exclude_end? (boolean) as ::JSON string.

Class Method Details

.json_create(object)

Deserializes JSON string by constructing new Range object with arguments a serialized by #to_json.

[ GitHub ]

  
# File 'ext/json/lib/json/add/range.rb', line 9

def self.json_create(object)
  new(*object['a'])
end

Instance Method Details

#as_json

Returns a hash, that will be turned into a ::JSON object and represent this object.

[ GitHub ]

  
# File 'ext/json/lib/json/add/range.rb', line 15

def as_json(*)
  {
    JSON.create_id  => self.class.name,
    'a'             => [ first, last, exclude_end? ]
  }
end

#to_json(*args)

Stores class name (Range) with ::JSON array of arguments a which include first (integer), last (integer), and exclude_end? (boolean) as ::JSON string.

[ GitHub ]

  
# File 'ext/json/lib/json/add/range.rb', line 25

def to_json(*args)
  as_json.to_json(*args)
end