Tbpgr Blog

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

Ruby | String | new

概要

String#new(string = "") -> String

詳細

string と同じ内容の新しい文字列を作成して返却

サンプルコード
require 'tbpgr_utils'

bulk_puts_eval binding, <<-EOS
"hoge" == String.new("hoge")
"hoge".eql? String.new("hoge")
"hoge".equal? String.new("hoge")
String.new.empty?
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

"hoge" == String.new("hoge")     # => true
"hoge".equal? String.new("hoge") # => false
String.new.empty?                # => true