Sha256: 5604b4306b43c2cab7499cb28300c70048be11fee4db9034d5c652144d64e21b
Contents?: true
Size: 1.67 KB
Versions: 16
Compression:
Stored size: 1.67 KB
Contents
#!/usr/bin/env ruby # -*- encoding: utf-8 -*- # Copyright Steffie 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
16 entries across 16 versions & 1 rubygems