Tbpgr Blog

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

Ruby | Kernel | Complex

概要

Kernel#Complex

詳細

実部が r、虚部が i である Complex クラスのオブジェクトを生成します。

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

bulk_puts_eval binding, <<-EOS
Complex(1)
Complex(1, 2)
Complex('1+1i')
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils
出力
Complex(1) # => (1+0i)
Complex(1, 2) # => (1+2i)
Complex('1+1i') # => (1+1i)