Sha256: e72c99d070129708a6275380784af0c8d8430769251a286df79286b4948f2725

Contents?: true

Size: 1.36 KB

Versions: 114

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8
require 'open_classes/object'
require 'open_classes/module'
require 'open_classes/array/together_helper'

# Array
class Array
  include TogetherHelper

  # Arrays bulk include?.
  #
  # together_include? has alias :tinclude?
  #
  # both include single ret case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_include? 5
  #   print ret # => true
  #
  # one include single ret case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_include? 9
  #   print ret # => true
  #
  # both not include single ret case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_include? 10
  #   print ret # => false
  #
  # both include multi ret case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_include? 5, true
  #   print ret # => [true, true]
  #
  # one include multi ret case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_include? 9, true
  #   print ret # => [false, true]
  #
  # both not include multi ret case
  #   lists = [[*1..5], [*5..9]]
  #   ret = lists.together_include? 10, true
  #   print ret # => [false, false]
  def together_include?(value, is_multi = false)
    if_not_contain_array_rails_type_error
    return reduce([]) { |ret, list|ret << list.include?(value) } if is_multi
    reduce(false) { |ret, list|ret = ret || list.include?(value) }
  end

  alias_method :tinclude?, :together_include?
end

Version data entries

114 entries across 114 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.150 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.149 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.148 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.147 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.146 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.145 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.144 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.143 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.142 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.141 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.140 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.139 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.138 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.137 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.136 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.135 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.134 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.133 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.132 lib/open_classes/array/together_include.rb
tbpgr_utils-0.0.131 lib/open_classes/array/together_include.rb