Tbpgr Blog

Organization Development Engineer tbpgr(てぃーびー) のブログ

ActiveSupport | Range#to_s

概要

Range#to_s

詳細

Range#to_s について

Range#to_s

範囲を文字列にする

サンプル

# encoding: utf-8
require 'active_support/core_ext/hash/keys'
require 'tbpgr_utils'

hash = {
  :key1 => :value1,
  :key2 => :value2,
  :key3 => :value3,
  "key4" => :value4,
}
bulk_puts_eval binding, <<-EOS
(1..5).to_s
('a'..'e').to_s
now = Time.now
(now..(now + 1)).to_s
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

(1..5).to_s # => "1..5"
('a'..'e').to_s # => "a..e"
now = Time.now # => 2014-03-25 12:21:35 +0900
(now..(now + 1)).to_s # => "2014-03-25 12:21:35 +0900..2014-03-25 12:21:36 +0900"