Module: Nanoc3::ArrayExtensions

Included in:
Array
Defined in:
lib/nanoc3/base/core_ext/array.rb

Instance Method Summary collapse

Instance Method Details

#checksumString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Calculates the checksum for this array. Any change to this array will result in a different checksum.

Returns:

  • (String)

    The checksum for this array



54
55
56
# File 'lib/nanoc3/base/core_ext/array.rb', line 54

def checksum
  Marshal.dump(self).checksum
end

#freeze_recursivelyvoid

This method returns an undefined value.

Freezes the contents of the array, as well as all array elements. The array elements will be frozen using #freeze_recursively if they respond to that message, or #freeze if they do not.

See Also:

  • Hash#freeze_recursively

Since:

  • 3.2.0



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nanoc3/base/core_ext/array.rb', line 36

def freeze_recursively
  return if self.frozen?
  freeze
  each do |value|
    if value.respond_to?(:freeze_recursively)
      value.freeze_recursively
    else
      value.freeze
    end
  end
end

#stringify_keysArray

Returns a new array where all items’ keys are recursively converted to strings by calling #stringify_keys or HashExtensions#stringify_keys.

Returns:

  • (Array)

    The converted array



21
22
23
24
25
# File 'lib/nanoc3/base/core_ext/array.rb', line 21

def stringify_keys
  inject([]) do |array, element|
    array + [ element.respond_to?(:stringify_keys) ? element.stringify_keys : element ]
  end
end

#symbolize_keysArray

Returns a new array where all items’ keys are recursively converted to symbols by calling #symbolize_keys or HashExtensions#symbolize_keys.

Returns:

  • (Array)

    The converted array



10
11
12
13
14
# File 'lib/nanoc3/base/core_ext/array.rb', line 10

def symbolize_keys
  inject([]) do |array, element|
    array + [ element.respond_to?(:symbolize_keys) ? element.symbolize_keys : element ]
  end
end