Class: Array

Inherits:
Object show all
Defined in:
lib/is_same/core_ext.rb,
lib/is_same/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#elements_matching(object = nil, &block) ⇒ Object

Return Array elements that are matching.

Parameters:

  • Object


108
109
110
# File 'lib/is_same/core_ext.rb', line 108

def elements_matching object=nil, &block
  self.select {|value| value.matching?(object, &block) } 
end

#elements_matching?(object = nil, &block) ⇒ Boolean

Check if any elements of an Array is same as argument.

Parameters:

  • Object

Returns:

  • (Boolean)

    Boolean



93
94
95
96
97
98
99
100
101
102
# File 'lib/is_same/core_ext.rb', line 93

def elements_matching? object=nil, &block
  matching = false
  self.each do |value|
    if value.matching? object, &block 
      matching = true
      break
    end
  end
  matching
end

#include_same?(object) ⇒ Boolean

For backward compliability

Returns:

  • (Boolean)


123
124
125
# File 'lib/is_same/core_ext.rb', line 123

def include_same? object
  elements_matching? object
end

#including_same(object) ⇒ Object

For backward compliability



127
128
129
# File 'lib/is_same/core_ext.rb', line 127

def including_same object
  elements_matching object
end