Singleton method not copied : singleton method « Class « Ruby
- Ruby
- Class
- singleton method
Singleton method not copied
s1 = "cat"
def s1.upcase
"CaT"
end
s1_dup = s1.dup
s1_clone = s1.clone
s1 #=> "cat"
s1_dup.upcase #=> "CAT" (singleton method not copied)
s1_clone.upcase #=> "CaT" (uses singleton method)
Related examples in the same category