Tbpgr Blog

Ruby プログラマ tbpgr(てぃーびー) のブログ

ActiveSupport | Range#range_overlaps?

概要

Range#range_overlaps?

詳細

Range#range_overlaps? について

Range#range_overlaps?

メソッドの範囲が重なっているかどうかを返却する

サンプル

# encoding: utf-8
require 'active_support/core_ext/range/overlaps'
require 'tbpgr_utils'

bulk_puts_eval binding, <<-EOS
(1..5).overlaps? (1..5)
(1..5).overlaps? (2..4)
(1..5).overlaps? (0..6)
(1..5).overlaps? (6..7)
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

(1..5).overlaps? (1..5) # => true
(1..5).overlaps? (2..4) # => true
(1..5).overlaps? (0..6) # => true
(1..5).overlaps? (6..7) # => false