Class: Range
- Inherits:
-
Object
- Object
- Range
- Defined in:
- lib/json/add/range.rb
Class Method Summary collapse
-
.json_create(object) ⇒ Object
Returns a new Range object constructed from
object['a']
, which must be an array of values suitable for a call to Range.new:.
Instance Method Summary collapse
-
#as_json ⇒ Object
Returns a 2-element hash representing
self
:. -
#to_json(*args) ⇒ Object
Returns a JSON string representing
self
:.
Class Method Details
.json_create(object) ⇒ Object
16 17 18 |
# File 'lib/json/add/range.rb', line 16 def self.json_create(object) new(*object['a']) end |
Instance Method Details
#as_json ⇒ Object
Returns a 2-element hash representing self
:
require 'json/add/range'
(1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
(1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
27 28 29 30 31 32 |
# File 'lib/json/add/range.rb', line 27 def as_json(*) { JSON.create_id => self.class.name, 'a' => [ first, last, exclude_end? ] } end |
#to_json(*args) ⇒ Object
Returns a JSON string representing self
:
require 'json/add/range'
(1..4).to_json # => "{\"json_class\":\"Range\",\"a\":[1,4,false]}"
(1...4).to_json # => "{\"json_class\":\"Range\",\"a\":[1,4,true]}"
('a'..'d').to_json # => "{\"json_class\":\"Range\",\"a\":[\"a\",\"d\",false]}"
41 42 43 |
# File 'lib/json/add/range.rb', line 41 def to_json(*args) as_json.to_json(*args) end |