Class: ConvenientService::Utils::Array::FindLast

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/array/find_last.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(array, &block) ⇒ void

Parameters:

  • array (Array, Enumerable)
  • block (Proc, nil)


24
25
26
27
# File 'lib/convenient_service/utils/array/find_last.rb', line 24

def initialize(array, &block)
  @array = array
  @block = block
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



11
12
13
# File 'lib/convenient_service/utils/array/find_last.rb', line 11

def array
  @array
end

#blockObject (readonly)

Returns the value of attribute block.



17
18
19
# File 'lib/convenient_service/utils/array/find_last.rb', line 17

def block
  @block
end

Instance Method Details

#callObject

Note:

Works with custom Enumerable objects.

Returns Can be any type.

Returns:

  • (Object)

    Can be any type.

See Also:



35
36
37
38
39
# File 'lib/convenient_service/utils/array/find_last.rb', line 35

def call
  array.reverse_each { |item| return item if block.call(item) }

  nil
end