Module: Gonzo::ArrayExtensions

Defined in:
lib/gonzo_array_extensions/array.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/gonzo_array_extensions/array.rb', line 3

def self.included(base)
  base.instance_eval do
    alias_method_chain :first, :block
    alias_method_chain :last, :block
    alias_method_chain :include?, :block
  end
end

Instance Method Details

#first_with_block(*args, &block) ⇒ Object



11
12
13
14
# File 'lib/gonzo_array_extensions/array.rb', line 11

def first_with_block(*args, &block)
  return first_without_block(*args) unless block_given?
  select(&block).first_without_block(*args)
end

#include_with_block?(*args, &block) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/gonzo_array_extensions/array.rb', line 21

def include_with_block?(*args, &block)
  return include_without_block?(*args) unless block_given?
  !select(&block).empty?
end

#last_with_block(*args, &block) ⇒ Object



16
17
18
19
# File 'lib/gonzo_array_extensions/array.rb', line 16

def last_with_block(*args, &block)
  return last_without_block(*args) unless block_given?
  select(&block).last_without_block(*args)
end