# Code to test some methods of the the String class. # Short method of creating a string. r = "cat" # Short method of creating a string. s = "dog" # Long method of creating a string. t = String.new("elephant") # Create an empty string. u = String.new( ) # Print values of strings. print "#{r} #{s} #{t} #{u}\n" # Test the upcase method (nondestructive). v = t.upcase print "#{t} #{v}\n" # Test the upcase method (destructive). w = t.upcase! print "#{t} #{w}\n" # Test the length method. print "#{r.length} #{s.length} #{t.length} #{u.length} #{v.length} #{w.length}\n" # Test the <=> method print r <=> s, " ", s <=> r, " ", s <=> "dog", "\n"