Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # DATA TYPES
  2.  
  3. # INTEGER
  4. # 2
  5. # 100029
  6.  
  7. # STRING
  8. # "Hello"
  9. # ""
  10. # " "
  11. # Interpolation
  12. name = "joao"
  13. age = 27
  14. "Hello #{name}, #{age}"
  15.  
  16. # Concatenation
  17. "Hello " + name + ", " + age.to_s
  18.  
  19. # Single vs Double quotes
  20. # puts "hello #{2 + 7}"
  21. # puts 'hello #{2 + 7}'
  22.  
  23. # FLOAT
  24. # 3.14
  25. # 1.2343
  26. 3.14.floor
  27. 3.14.ceil
  28. 3.14.truncate
  29.  
  30. # ARRAY
  31. # List of elements
  32. beatles = ["john", "paul", "ringo", "george"]
  33. beatles.sort
  34. beatles.count
  35.  
  36.  
  37.  
  38. # NIL
  39. nil
  40. # absence of value
  41.  
  42. # BOOLEANS
  43. true.class # => TrueClass
  44. false.class # => FalseClass
  45.  
  46. # RANGE
  47. # (1..5) # range from 1 to 5
  48. # (1...5) # range from 1 to 4
  49.  
  50. # Casting (changing the data type)
  51. # "1991".to_i # => 1991
  52. # "1991".to_f # => 1991.0
  53. # (1..5).to_a # => [1,2,3,4,5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement