Sha256: f8e04b332a0ce2eb40df138a0eecfc78fdc43b5e65154d6dd4f86b40c4355d85

Contents?: true

Size: 762 Bytes

Versions: 2

Compression:

Stored size: 762 Bytes

Contents

module OptionsHelper
  # Internal: Deep clone a Hash. Compute the values in the Hash if responding to :call
  #
  # options - The Hash options to clone
  #
  # Returns the cloned Hash with values computed if responding to :call
  def deep_clone(options = {})
    compute_values(options)
    Marshal.load(Marshal.dump(options)) # deep cloning options
  end

  # Internal: Recursively compute the value of a Hash if it responds to :call
  #
  # options - The Hash options to compute value for
  #
  # Returns the Hash with values computed if responding to :call
  def compute_values(options = {})
    options.each do |k, v|
      if v.is_a?(Hash)
        compute_values(v)
      else
        options[k] = v.call if v.respond_to?(:call)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
message_queue-0.1.1 lib/message_queue/options_helper.rb
message_queue-0.1.0 lib/message_queue/options_helper.rb