Tbpgr Blog

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

Ruby | Range | exclude_end?

概要

Range#exclude_end? -> bool

詳細

範囲オブジェクトが終端を含まないとき真を返却

サンプルコード
require 'tbpgr_utils'


bulk_puts_eval binding, <<-EOS
(2..5).exclude_end?
(2...5).exclude_end?
Range.new(2, 5).exclude_end?
Range.new(2, 5, false).exclude_end?
Range.new(2, 5, true).exclude_end?
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

(2..5).exclude_end?                 # => false
(2...5).exclude_end?                # => true
Range.new(2, 5).exclude_end?        # => false
Range.new(2, 5, false).exclude_end? # => false
Range.new(2, 5, true).exclude_end?  # => true