learn_ruby_ch2_pt3 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

If statement, check for zero

A

value = 0

if value.zero? then
puts “value is zero.”
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Array example (pacific)

Hash example

A

pacific = [ “Washington”, “Oregon”, “California”]
pacific[0] # => “Washington”

pacific = { “WA” => “Washington”, “OR” => “Oregon”, “CA” => “California” }
pacific[“OR”] # => “Oregon”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

define a method (hello) and then undefine the method

A

def hello
puts “Hello”
end

hello # => Hello

undef hello

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

define a method (repeat) with arguments

A

def repeat( word, times )
puts word * times
end

repeat(“Hello! “, 3) # => Hello! Hello! Hello!
repeat “Good-bye! “, 4 # => Good-bye! Good-bye! Good-bye! Good-bye!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

return a value

A

In Ruby, the last value in a method is returned, with or without an explicit return statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly