Sha256: 5b71fe5e47d3c853c9daa40648b907f395e3f975fb2c259f5da148961216c95c

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module Kernel
  # Override this in a child class if it cannot be dup'ed.
  #
  #   obj1 = Object.new
  #   obj2 = obj1.try_dup
  #   obj2.equal?(obj1)    #=> false
  #
  # CREDIT: Dan Kubb (extlib)
  def try_dup
    dup
  end

  # Alternative name for #try_dup.
  def dup!
    try_dup
  end
end

class TrueClass
  # Since TrueClass is immutable it cannot be duplicated.
  # For this reason #try_dup returns +self+.
  #
  #   true.try_dup  #=> true
  #
  def try_dup
    self
  end
end

class FalseClass
  # Since FalseClass is immutable it cannot be duplicated.
  # For this reason #try_dup returns +self+.
  #
  #   false.try_dup  #=> false
  #
  def try_dup
    self
  end
end

class NilClass
  # Since NilClass is immutable it cannot be duplicated.
  # For this reason #try_dup returns +self+.
  #
  #   nil.try_dup  #=> nil
  #
  def try_dup
    self
  end
end

class Numeric
  # Since Numeric is immutable it cannot be duplicated.
  # For this reason #try_dup returns +self+.
  #
  #   1.try_dup  #=> 1
  #
  def try_dup
    self
  end
end

class Symbol
  # Since Symbol is immutable it cannot be duplicated.
  # For this reason #try_dup returns +self+.
  #
  #   :a.try_dup  #=> :a
  #
  def try_dup
    self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-2.9.0.pre.1 lib/core/facets/kernel/try_dup.rb