Section 1

Preview this deck

Methods

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (8)

Section 1

(8 cards)

Methods

Front

def sayhi(name, age) puts ("hello " + name + " you are " + age.to_s) end sayhi("Mike", 42)

Back

puts vs. print

Front

Puts will print out what you specify with new line Print will print output without a new line

Back

Comments

Front

# comment OR =begin =end

Back

Setting Defaults in Methods

Front

If method has no value, then will default to assigned values. def sayhi(name= "No name", age= 0) puts ("hello " + name + " you are " + age.to_s) end sayhi

Back

IF | ELSE | ELSIF

Front

if x < y # Assumes x and y are defined puts "x is less than y!" elsif x > y puts "x is greater than y!" else puts "x equals y!" end

Back

Returns in method

Front

Back

Hash

Front

states = { :California => "CA", "New York" => "NY", 1 => "OR" } puts states[:California]

Back

Array

Front

friends = ['Kevin', 'Karen', "Oscar"] puts friends[0, 2] # stops at Karen puts friends[0] = "Dwight" # Replaces Kevin with Dwight

Back