Tbpgr Blog

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

Ruby | String | ascii_only?

概要

String#ascii_only? -> bool

詳細

文字列がASCII文字のみで構成されている場合に true を返却

サンプルコード
require 'tbpgr_utils'

bulk_puts_eval binding, <<-EOS
'hoge'.ascii_only?
''.ascii_only?
'ほgeascii_only?'.ascii_only?
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

'hoge'.ascii_only? # => true
''.ascii_only?     # => true
'ほge'.ascii_only? # => false