Singleton method not copied : singleton method « Class « Ruby






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

1.Add singleton method to a string instance
2.Add a singleton method to a instance object
3.Use extend to include a module to create single methods