Module: Nanoc3::ArrayExtensions
- Included in:
- Array
- Defined in:
- lib/nanoc3/base/core_ext/array.rb
Instance Method Summary collapse
-
#checksum ⇒ String
private
Calculates the checksum for this array.
-
#freeze_recursively ⇒ void
Freezes the contents of the array, as well as all array elements.
-
#stringify_keys ⇒ Array
Returns a new array where all items’ keys are recursively converted to strings by calling #stringify_keys or HashExtensions#stringify_keys.
-
#symbolize_keys ⇒ Array
Returns a new array where all items’ keys are recursively converted to symbols by calling #symbolize_keys or HashExtensions#symbolize_keys.
Instance Method Details
#checksum ⇒ String
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.
54 55 56 |
# File 'lib/nanoc3/base/core_ext/array.rb', line 54 def checksum Marshal.dump(self).checksum end |
#freeze_recursively ⇒ void
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.
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_keys ⇒ Array
Returns a new array where all items’ keys are recursively converted to strings by calling #stringify_keys or HashExtensions#stringify_keys.
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_keys ⇒ Array
Returns a new array where all items’ keys are recursively converted to symbols by calling #symbolize_keys or HashExtensions#symbolize_keys.
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 |