Skip to content

Instantly share code, notes, and snippets.

@santosh79
Created November 16, 2009 02:58
Show Gist options
  • Save santosh79/235687 to your computer and use it in GitHub Desktop.
Save santosh79/235687 to your computer and use it in GitHub Desktop.
#The clone method also copies over the singleton methods of the receiver
porsche = Object.new
def porsche.number_of_wheels
4
end
puts "porsche has #{porsche.number_of_wheels}"
porsche_clone = porsche.clone
puts "porsche's clone has #{porsche_clone.number_of_wheels}"
#The dup method does NOT copy over singleton methods
porsche_dup = porsche.dup
#This throws a NoMethodError
#puts "porsche's dup has #{porsche_dup.number_of_wheels}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment