Class: ConvenientService::Utils::Array::Rjust

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(array, size, pad = nil) ⇒ void

Parameters:

  • array (Array)
  • size (Integer)
  • pad (Object) (defaults to: nil)

    Can be any type.



31
32
33
34
35
# File 'lib/convenient_service/utils/array/rjust.rb', line 31

def initialize(array, size, pad = nil)
  @array = array
  @size = size
  @pad = pad
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



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

def array
  @array
end

#padObject (readonly)

Returns the value of attribute pad.



23
24
25
# File 'lib/convenient_service/utils/array/rjust.rb', line 23

def pad
  @pad
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

Instance Method Details

#callArray

Returns:



40
41
42
43
44
45
46
# File 'lib/convenient_service/utils/array/rjust.rb', line 40

def call
  return array if size <= array.size

  count = size - array.size

  array + [pad] * count
end