Tbpgr Blog

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

ActiveSupport | Range#include?

概要

Range#include?

詳細

Range#include? について

Range#include?

引数が範囲に含まれているか確認する

サンプル

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

bulk_puts_eval binding, <<-EOS
(1..5).include? 1
(1..5).include? 5
(1..5).include? 6
(1..5).include? (1..5)
(1..5).include? (2..4)
(1..5).include? (1..6)
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

(1..5).include? 1 # => true
(1..5).include? 5 # => true
(1..5).include? 6 # => false
(1..5).include? (1..5) # => true
(1..5).include? (2..4) # => true
(1..5).include? (1..6) # => false