Module: Delight::Enumerator::SelectByMethods

Defined in:
lib/delight/enumerator/select_by_methods.rb

Instance Method Summary collapse

Instance Method Details

#select_byArray

Filter collection elements using method calls and values passed as keyword arguments.

Examples:

["String", 1, 3, :symbol, 'string'].select_by(class: String)
  # => ["String", 'string']

Person = Struct.new(:name, :age)

people = [
  Person.new("John", 30),
  Person.new("Jane", 25),
  Person.new("Alice", 30),
]

people.select_by(age: 30)
# => [
#  Person.new("John", 30),
#  Person.new("Alice", 30),
# ]

Returns:

  • (Array)

    containingg elements that match the passed arguments.



27
28
29
30
31
# File 'lib/delight/enumerator/select_by_methods.rb', line 27

def select_by(**)
  select do |element|
    collection_matcher(element, **)
  end
end