Sha256: 66dd0acaf5c15f2f2c6a570a1d283feb942d99653d970735e97c17d23a5d1270

Contents?: true

Size: 1 KB

Versions: 17

Compression:

Stored size: 1 KB

Contents

module CoreExtensions
  module Object
    def deep_clone
      case self
      when Fixnum, Bignum, 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 = clone
      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 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

17 entries across 17 versions & 1 rubygems

Version Path
card-1.92.2 config/initializers/01_core_extensions/object.rb
card-1.92.1 config/initializers/01_core_extensions/object.rb
card-1.92 config/initializers/01_core_extensions/object.rb
card-1.91 config/initializers/01_core_extensions/object.rb
card-1.21.0 config/initializers/01_core_extensions/object.rb
card-1.20.4 config/initializers/01_core_extensions/object.rb
card-1.20.3 config/initializers/01_core_extensions/object.rb
card-1.20.2 config/initializers/01_core_extensions/object.rb
card-1.20.1 config/initializers/01_core_extensions/object.rb
card-1.20.0 config/initializers/01_core_extensions/object.rb
card-1.19.6 config/initializers/01_core_extensions/object.rb
card-1.19.5 config/initializers/01_core_extensions/object.rb
card-1.19.4 config/initializers/01_core_extensions/object.rb
card-1.19.3 config/initializers/01_core_extensions/object.rb
card-1.19.2 config/initializers/01_core_extensions/object.rb
card-1.19.1 config/initializers/01_core_extensions/object.rb
card-1.19.0 config/initializers/01_core_extensions/object.rb