learn_ruby_ch3_pt2 Flashcards

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

Ternary operator (argument, arguments)

A

label = length == 1 ? “ argument” : “ arguments”

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

case statement

lang = “fr”

A

lang = “fr”

dog = case lang
  when "en"
     "dog"
  when "es"
     "perro"
  when "fr"
     "chien"
  else
     "dog"
end

colon form no longer supported starting in 1.9, e.g.,
when “en”: “dog”

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

while array loop (breeds)

A

i = 0
breeds = [ “quarter”, “arabian”, “appalosa”, “paint” ]
puts breeds.size # => 4
temp = []

while i < breeds.size do
temp &laquo_space;breeds[i].capitalize
i +=1
end

temp.sort! # => [“Appalosa”, “Arabian”, “Paint”, “Quarter”]
breeds.replace( temp )
p breeds # => [“Appalosa”, “Arabian”, “Paint”, “Quarter”]

The “do” is optional

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

begin while loop (temp)

A

temp = 98.3

begin
print “Temp is “ + temp.to_s + “ Fahrenheit. “
temp += 0.1
end while temp < 98.6

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

while with break (breeds)

A
i = 0
breeds = [ "quarter", "arabian", "appalosa", "paint" ]
temp = []
while i < breeds.size
  temp << breeds[i].capitalize
  break if temp[i] == "Arabian"
  i +=1
end

p temp # => [“Quarter”, “Arabian”]

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