Module: Wallaby::Utils
- Defined in:
- lib/utils/wallaby/utils.rb
Overview
:nodoc:
Defined Under Namespace
Classes: HashCloner
Class Method Summary collapse
-
.clone(object) ⇒ Object
A cloned object.
-
.inspect(object) ⇒ String
Inspection string for the given object.
Class Method Details
.clone(object) ⇒ Object
Returns a cloned object.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/utils/wallaby/utils.rb', line 7 def self.clone(object) # NOTE: Neither marshal/deep_dup/dup is able to make a correct deep copy, # therefore, this is our solution: case object when Hash HashCloner.execute(object) when Array object.each_with_object(object.class.new) { |value, array| array << clone(value) } when Class # NOTE: `Class.dup` turns the origin Class object into an anonymous clone. # therefore, the Class object itself should be returned instead object else object.dup end end |
.inspect(object) ⇒ String
Returns inspection string for the given object.
26 27 28 29 30 31 |
# File 'lib/utils/wallaby/utils.rb', line 26 def self.inspect(object) return 'nil' if object.nil? return "#{object.class}##{object.try(:id)}" if object.is_a?(::ActiveRecord::Base) object.inspect end |