Ruby 2.3.0 リファレンスマニュアル > ライブラリ一覧 > json/add/rationalライブラリ > Rationalクラス > to_json
to_json(*args) -> String
[permalink][rdoc] [added by json/add/rational]
自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
require 'json/add/rational'
Rational(1, 3).to_json # => "{\"json_class\":\"Rational\",\"n\":1,\"d\":3}"