#from http://pragmaticprogrammer.com/titles/ruby/code/smp383.html # comments added # equivalent to pr382.rb a = "hello" b = a.dup def a.to_s # adds a class to object a "The value is '#{self}'" end def a.two_times # uses the same virtual class self + self end p a.to_s p a.two_times p b.to_s