Class: ConvenientService::Utils::Array::LimitedPush

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

Defined Under Namespace

Modules: Constants

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(array, object, limit: Constants::DEFAULT_LIMIT) ⇒ void

Parameters:



37
38
39
40
41
# File 'lib/convenient_service/utils/array/limited_push.rb', line 37

def initialize(array, object, limit: Constants::DEFAULT_LIMIT)
  @array = array
  @object = object
  @limit = limit
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



18
19
20
# File 'lib/convenient_service/utils/array/limited_push.rb', line 18

def array
  @array
end

#limitObject (readonly)

Returns the value of attribute limit.



30
31
32
# File 'lib/convenient_service/utils/array/limited_push.rb', line 30

def limit
  @limit
end

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

Instance Method Details

#callArray<Object>

Returns:



46
47
48
49
50
# File 'lib/convenient_service/utils/array/limited_push.rb', line 46

def call
  return array if array.size >= limit

  array.push(object)
end