Sha256: 32e953af502f26465de9463f940ec17709b482707fb6c4f98ce52d7b59581f0c
Contents?: true
Size: 1.58 KB
Versions: 13
Compression:
Stored size: 1.58 KB
Contents
module CoreExtensions module Object def deep_clone case self when Integer, Float, NilClass, FalseClass, TrueClass, Symbol klone = self when Hash klone = clone each { |k, v| klone[k] = v.deep_clone } when Array klone = clone klone.clear each { |v| klone << v.deep_clone } else klone = if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4") && (self.is_a?(Fixnum) || self.is_a?(Bignum)) self else clone end end klone.deep_clone_instance_variables klone end def send_unless method, *args, &_block (block_given? ? yield : self) || send(method, *args) end def send_if method, *args, &_block (block_given? ? yield : self) && send(method, *args) end def to_name Card::Name.new self end def name? # Although we want to check for instances of class Card::Name we can't use that # class because it is renewed with every request # (at least in development mode) but the name cache is persistent. # Hence the name objects in the cache are objects of a different instance of the # Card::Name class and is_a?(Card::Name) will return false self.is_a? Cardname end def to_viewname Card::Name::ViewName.new self end def deep_clone_instance_variables instance_variables.each do |v| instance_variable_set v, instance_variable_get(v).deep_clone end end def in? other other.include? self end end end
Version data entries
13 entries across 13 versions & 1 rubygems