Sha256: ee7ed4e29232ea3b2d38afdc7a5589a638404813728de355cc1553197a4f66e1
Contents?: true
Size: 1.66 KB
Versions: 15
Compression:
Stored size: 1.66 KB
Contents
#!/usr/bin/env ruby # -*- encoding: utf-8 -*- # Copyright Steffi Dorn <mail@muflax.com>, 2017 # License: GNU APGLv3 (or later) <http://www.gnu.org/copyleft/gpl.html> class Object def deep_dup duplicable? ? dup : self end end class Array def deep_dup map(&:deep_dup) end end class Hash def deep_dup hash = dup each_pair do |key, value| if key.frozen? && ::String === key hash[key] = value.deep_dup else hash.delete(key) hash[key.deep_dup] = value.deep_dup end end hash end end # duplicable? require "bigdecimal" class Object ; def duplicable? ; true ; end ; end class BigDecimal ; def duplicable? ; true ; end ; end class Method ; def duplicable? ; false ; end ; end class NilClass ; begin ; nil.dup ; rescue TypeError ; def duplicable? ; false ; end ; end ; end class FalseClass ; begin ; false.dup ; rescue TypeError ; def duplicable? ; false ; end ; end ; end class TrueClass ; begin ; true.dup ; rescue TypeError ; def duplicable? ; false ; end ; end ; end class Symbol ; begin ; :symbol.dup; "symbol_from_string".to_sym.dup ; rescue TypeError ; def duplicable? ; false ; end ; end ; end class Numeric ; begin ; 1.dup ; rescue TypeError ; def duplicable? ; false ; end ; end ; end class Complex ; begin ; Complex(1).dup ; rescue TypeError ; def duplicable? ; false ; end ; end ; end class Rational ; begin ; Rational(1).dup ; rescue TypeError ; def duplicable? ; false ; end ; end ; end
Version data entries
15 entries across 15 versions & 1 rubygems