Tbpgr Blog

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

Ruby | String | <<

概要

String#<< other -> self
String#concat(other) -> self

詳細

self に文字列 other を破壊的に連結。
other が 0 から 255 のまでの整数の場合はASCIIコードで対応する文字を結合する。
self を返します。

サンプルコード
require 'tbpgr_utils'

base = "base"
bulk_puts_eval binding, <<-EOS
base << "plus"
base
base.concat "plus"
base
base << 65
base
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

base << "plus"     # => "baseplus"
base               # => "baseplus"
base.concat "plus" # => "baseplusplus"
base               # => "baseplusplus"
base << 65         # => "baseplusplusA"
base               # => "baseplusplusA"