Home‎ > ‎Ruby‎ > ‎CodeAcademy Notes‎ > ‎

Intro


Variables and Data Types

Data Types: Numbers Strings Boolean:
my_num = 25          # raw number
my_boolean = true    # true/1 false/0
my_string =  "Ruby"  # stings in double quotes

Variables:
my_num = 100

Math
5+5  # add
5-5  # subtract
5*5  # times
5/5  # divide
5**2 # exponent
10%3 # modulo

Puts and Prints
print "hello world \n" # print with a return
puts "hello world"     # print with a return

String Methods

.length Method
"I like coffee".length # value of 13

.reverse Method
"chuck".reverse # value of kcuhc

.upcase & downcase
"Chuck".upcase   # equals CHUCK
"Chuck".downcase # equals chuck

Writing Good Code

Single Line Comments
 # comment

Multi-Line Comments
 =begin
 comment1
 comment2
 =end

Naming Conventions
var1     # all lowercase
var_two  # separated with underscore



Comments