Tbpgr Blog

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

ActiveSupport | Enumerable#many?

概要

Enumerable#many?

詳細

Enumerable#many? について

Enumerable#many?

size > 1

サンプル

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

I18n.enforce_available_locales = true
bulk_puts_eval binding, <<-EOS
[].many?
[1].many?
[1, 2].many?
[1, 2, 3].many? {|v| v.even?}
[1, 2, 3, 4].many? {|v| v.even?}
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

[].many? # => false
[1].many? # => false
[1, 2].many? # => true
[1, 2, 3].many? {|v| v.even?} # => false
[1, 2, 3, 4].many? {|v| v.even?} # => true