Sha256: 527e991f3b9c8f16f705ba51e625990f70231a948883f00aceb8b49976a5c303

Contents?: true

Size: 1.13 KB

Versions: 30

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

# @api private
module Nanoc::ArrayExtensions
  # Returns a new array where all items' keys are recursively converted to
  # symbols by calling {Nanoc::ArrayExtensions#__nanoc_symbolize_keys_recursively} or
  # {Nanoc::HashExtensions#__nanoc_symbolize_keys_recursively}.
  #
  # @return [Array] The converted array
  def __nanoc_symbolize_keys_recursively
    array = []
    each do |element|
      array << (element.respond_to?(:__nanoc_symbolize_keys_recursively) ? element.__nanoc_symbolize_keys_recursively : element)
    end
    array
  end

  # Freezes the contents of the array, as well as all array elements. The
  # array elements will be frozen using {#__nanoc_freeze_recursively} if they respond
  # to that message, or #freeze if they do not.
  #
  # @see Hash#__nanoc_freeze_recursively
  #
  # @return [void]
  def __nanoc_freeze_recursively
    return if frozen?
    freeze
    each do |value|
      if value.respond_to?(:__nanoc_freeze_recursively)
        value.__nanoc_freeze_recursively
      else
        value.freeze
      end
    end
  end
end

# @api private
class Array
  include Nanoc::ArrayExtensions
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
nanoc-4.9.4 lib/nanoc/base/core_ext/array.rb
nanoc-4.9.3 lib/nanoc/base/core_ext/array.rb
nanoc-4.9.2 lib/nanoc/base/core_ext/array.rb
nanoc-4.9.1 lib/nanoc/base/core_ext/array.rb
nanoc-4.9.0 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.19 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.18 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.17 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.16 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.15 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.14 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.13 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.12 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.11 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.10 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.9 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.8 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.7 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.6 lib/nanoc/base/core_ext/array.rb
nanoc-4.8.5 lib/nanoc/base/core_ext/array.rb