Ruby

From Dave's wiki
Jump to navigation Jump to search

Notes taken from http://tryruby.org/levels/1/challenges/0

#reverse a string
"Jimmy".reverse
#length method
"Jimmy".length
#repeat string
"Jimmy" * 5
#turn number into string
40.to_s.reverse
#convert to integers
to_i
#convert to arrays
to_a
#list of numbers
[12, 47, 35]
#get max in a list of numbers
[12, 47, 35].max
#assigning a list
ticket = [12, 47, 35]
#sort list
ticket.sort
#hash
#when you play a colon in front of a simple word, you get a symbol
books["Gravity's Rainbow"] = :splendid