Guest User

Untitled

a guest
May 17th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. def sayGoodnight(name)
  2. return "Goodnight, " + name
  3. end
  4.  
  5. def otherWayToSayGoodnight(name)
  6. "Goodnight, #{name}"
  7. end
  8.  
  9. puts sayGoodnight("John-Boy")
  10. puts otherWayToSayGoodnight("Richard")
  11.  
  12. a = [1, 'cat', 42]
  13.  
  14. # Set second item to dog
  15. a[1] = 'dog'
  16.  
  17. # Write it
  18. puts a[1]
  19.  
  20. a = %w(ant bee cat dog elk)
  21. # Print item 3
  22. puts a[2]
  23.  
  24. # Hash
  25. fruits = {
  26. 'apple' => 'red',
  27. 'pear' => 'green',
  28. 'banana' => 'yellow',
  29. }
  30.  
  31. puts "Which color is an apple? I guess it's #{fruits['apple']}"
  32.  
  33. # Give N a value
  34. n = 3.14
  35.  
  36. # Play with N
  37. if n > 2
  38. puts "N is higher than 2"
  39. elsif n > 900
  40. puts "N is over 9000!"
  41. else
  42. puts "Either N is lower than 2, or not a number!"
  43. end
  44.  
  45. n = 1
  46.  
  47. # While loop, 3 times
  48. while n <= 3
  49. puts "N is #{n}"
  50. n += 1
  51. end
  52.  
  53. # Statement modifer
  54. puts "N is now over 3" if n > 3
  55. puts "N is in fact #{n}"
Add Comment
Please, Sign In to add comment