Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Ruby2.1新規要素 | Rational型のリテラルの追加

概要

Rational型のリテラルの追加

詳細

Rational型を表す新たなリテラル表記が追加されました。

サンプルコード
# encoding: utf-8
require 'tbpgr_utils'

bulk_puts_eval binding, <<-EOS
1/3r
(1/3r).class
((1/3r)*3).to_i
EOS
出力
1/3r # => (1/3)
(1/3r).class # => Rational
((1/3r)*3).to_i # => 1