Created
November 16, 2009 02:58
-
-
Save santosh79/235687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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