TKVR

Chris Pine, Learn to Program Chapter 2 - Letters

Feb 16th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.71 KB | None | 0 0
  1. puts 'Hello, world!'
  2. puts ''
  3. puts 'Good-bye.'
  4.  
  5. # no space adding strings
  6. puts 'I like' + 'apple pie.'
  7.  
  8. # spaces matter inside of strings
  9. puts 'I like ' + 'apple pie.'
  10. puts 'I like' + ' apple pie.'
  11.  
  12. # multiply strings
  13. puts 'blink ' * 4
  14.  
  15. # numbers vs. digits
  16. puts 12 + 12
  17. puts '12' + '12'
  18. puts '12 + 12'
  19. puts 2 * 5
  20. puts '2' * 5
  21. puts '2 * 5'
  22.  
  23. # problems with strings - #<TypeError: can't convert Fixnum into String>
  24. # puts '12' + 12
  25. # puts 'Fred' * 'John'
  26. # puts 'Will' + 12
  27.  
  28. # let the computer know I want to stay in the string with backslash (escape character for apostrophe and backslash itself)
  29. puts 'You\'re swell!'
  30. puts 'backslash at the end of a string: \\'
  31. puts 'up\\down'
  32. puts 'up\down'
Add Comment
Please, Sign In to add comment