Skip to content

Commit

Permalink
Reindented
Browse files Browse the repository at this point in the history
  • Loading branch information
flori committed Jan 2, 2015
1 parent 1f339fe commit 3869d77
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/json/add/rational.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
defined?(::Rational) or require 'rational'

class Rational

# Deserializes JSON string by converting numerator value <tt>n</tt>, denominator
# value <tt>d</tt>, to a Rational object.
# Deserializes JSON string by converting numerator value <tt>n</tt>,
# denominator value <tt>d</tt>, to a Rational object.
def self.json_create(object)
Rational(object['n'], object['d'])
end
Expand All @@ -15,14 +14,14 @@ def self.json_create(object)
# object.
def as_json(*)
{
JSON.create_id => self.class.name,
'n' => numerator,
'd' => denominator,
JSON.create_id => self.class.name,
'n' => numerator,
'd' => denominator,
}
end

# Stores class name (Rational) along with numerator value <tt>n</tt> and denominator value <tt>d</tt> as JSON string
def to_json(*)
as_json.to_json
end
end
end

0 comments on commit 3869d77

Please sign in to comment.