module Mixlib::CLI::InheritMethods
Public Instance Methods
deep_dup(object)
click to toggle source
- object
-
Instance to clone
This method will return a “deep clone” of the provided ‘object`. If the provided `object` is an enumerable type the contents will be iterated and cloned as well.
# File lib/mixlib/cli.rb, line 52 def deep_dup(object) cloned_object = object.respond_to?(:dup) ? object.dup : object if cloned_object.kind_of?(Enumerable) if cloned_object.kind_of?(Hash) new_hash = cloned_object.class.new cloned_object.each do |key, value| cloned_key = deep_dup(key) cloned_value = deep_dup(value) new_hash[cloned_key] = cloned_value end cloned_object.replace(new_hash) else cloned_object.map! do |shallow_instance| deep_dup(shallow_instance) end end end cloned_object rescue TypeError # Symbol will happily provide a `#dup` method even though # attempts to clone it will result in an exception (atoms!). # So if we run into an issue of TypeErrors, just return the # original object as we gave our "best effort" object end
inherited(receiver)
click to toggle source
# File lib/mixlib/cli.rb, line 43 def inherited(receiver) receiver.options = deep_dup(self.options) receiver.extend(Mixlib::CLI::InheritMethods) end