Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 20th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. string = String.new  # or name = ""
  2. string.concat('Rika')    # => Rika
  3. string.upcase    # => RIKA
  4. string.downcase  # => rika
  5. string.reverse   # => akiR
  6. string.split('') # => ["R", "i", "k", "a"]
  7.  
  8. array = Array.new  # or array = []
  9. array.push(1)  # => [1]
  10. array.push(2)  # => [1, 2]
  11. array.push(3)   # => [1, 2, 3]
  12. array.reverse  # => [3, 2, 1]
  13. array.first    # => 1
  14. array.last     # => 3
  15. array[0]       # => 1
  16. array[1]       # => 2
  17. array[2]       # => 3
  18.  
  19. hash = Hash.new # or hash = {}
  20. hash['first'] = "Rika" # => { 'first' => 'Rika' }
  21. hash['last'] = "Fama"  # => { 'first' => 'Rika', 'last' => 'Fama' }
  22.  
  23. hash['first']  # => Rika
  24. hash['last']   # => Fama
  25.  
  26. hash['first_name'].reverse  # => akiR
  27.  
  28. array.push(name)    # => [1, 2, 3, { 'first' => 'Rika', 'last' => 'Fama' } ]
  29. array.last          # => { 'first' => 'Rika', 'last' => 'Fama' }