Tbpgr Blog

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

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

概要

Complex型のリテラルの追加

詳細

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

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

v1 = Complex(0, 2)
v2 = Complex(2, 2)
bulk_puts_eval binding, <<-EOS
2i
2i.class
v1
v1.class
v2
v2.class
v2 + 2i
EOS
出力
2i # => (0+2i)
2i.class # => Complex
v1 # => (0+2i)
v1.class # => Complex
v2 # => (2+2i)
v2.class # => Complex
v2 + 2i # => (2+4i)