Tbpgr Blog

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

ActiveSupport | Enumerable#exclude?

概要

Enumerable#exclude?

詳細

Enumerable#exclude? について

Enumerable#exclude?

include?の否定

サンプル

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

I18n.enforce_available_locales = true
bulk_puts_eval binding, <<-EOS
[].exclude? 1
[1].exclude? 1
[1].exclude? 2
[1, 2].exclude? 1
[1, 2].exclude? 3
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

[].exclude? 1 # => true
[1].exclude? 1 # => false
[1].exclude? 2 # => true
[1, 2].exclude? 1 # => false
[1, 2].exclude? 3 # => true