Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby clone vs dup

class Klass
  attr_accessor :str
end

module Foo
  def foo; 'foo'; end
end

s1 = Klass.new #=> #<Klass:0x401b3a38>
s1.extend(Foo) #=> #<Klass:0x401b3a38>
s1.foo #=> "foo"

s2 = s1.clone #=> #<Klass:0x401b3a38>
s2.foo #=> "foo"

s3 = s1.dup #=> #<Klass:0x401b3a38>
s3.foo #=> NoMethodError: undefined method `foo' for #<Klass:0x401b3a38>

# While clone is used to duplicate an object, including its internal 
#state, dup typically uses the class of the descendant object to create 
#the new instance.
Comment

PREVIOUS NEXT
Code Example
Ruby :: ruby how to filter through excel 
Ruby :: ruby array of symbols 
Ruby :: rails rspec destroy data after each test 
Ruby :: simple form change id 
Ruby :: mobile money flutterwave payment 
Ruby :: deliver_later not sending mail in sidekiq in rails 
Ruby :: ruby adding an item to a hash 
Ruby :: ruby block_given? method 
Ruby :: rails render json only some attributes 
Ruby :: ruby zip rows and columns 
Ruby :: include? reverse ruby 
Ruby :: expect method call inside rescue rspec 
Ruby :: encryption and decryption in rails 
Ruby :: ruby file copy 
Ruby :: ruby hash merge vs merge! 
Ruby :: class ruby 
R :: convert latin accents to ascii R 
R :: r type of all columns 
R :: reverse row order dataframe R 
R :: r merge multiple data frames at once 
R :: r bar plot 
R :: r dictionary 
R :: R get specific character from string 
R :: convert string to lowercase R 
R :: how to throw an error in R 
R :: find nas in dataframe r 
R :: how to bootstrap in r 
R :: in r corr Cannot compute exact p-value with ties 
R :: r code mutate 
R :: exp() function R 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =