In Ruby, a dash may not be used in a
variable name…
…but before Ruby 2.1, one variable
was allowed to be named with a dash.
What was it called?
Question 1:
Slide 3
Slide 3 text
In Ruby, a dash may not be used in a
variable name…
…but before Ruby 2.1, one variable
was allowed to be named with a dash.
What was it called?
Hint: It’s a global variable.
Question 1:
Why can’t variable names
contain dashes?
Bonus Question:
Answer: Because the Ruby parser can’t distinguish it from the
minus (-) operator between two variables (e.g. forty-two).
Slide 7
Slide 7 text
Ruby may define a special File
object in the first file it interprets.
What is it called?
What does it do?
Question 2:
Slide 8
Slide 8 text
Ruby may define a special File
object in the first file it interprets.
What is it called?
Question 2:
Hint: When you call read, it reads the file, starting after
__END__
Slide 9
Slide 9 text
DATA
Answer 2:
Slide 10
Slide 10 text
What happens if you call:
DATA.rewind
before
DATA.read
Bonus Question:
Slide 11
Slide 11 text
What happens if you call:
DATA.rewind
before
DATA.read
Bonus Question:
Answer: It reads the entire file, including the source code.
Slide 12
Slide 12 text
The following line of code is
valid Ruby syntax:
a = true && return
But this line of code is not:
a = return && true
What is the error message?
Question 3:
Slide 13
Slide 13 text
void value
expression
Answer 3:
Slide 14
Slide 14 text
When you convert the range:
(1..3).to_a
You get the array:
[1, 2, 3]
What is the result of:
(3..1).to_a
Question 4:
Slide 15
Slide 15 text
[]
Answer 4:
Slide 16
Slide 16 text
What method would need to be
added to the Range interface to
make descending sequences
possible?
Bonus Question:
Slide 17
Slide 17 text
What method would need to be
added to the Range interface to
make descending sequences
possible?
Bonus Question:
Answer: pred (the opposite of succ).
Slide 18
Slide 18 text
What Ruby class mixes-in
Comparable but doesn’t define
the spaceship (<=>) operator?
Question 5:
Slide 19
Slide 19 text
What Ruby class mixes-in
Comparable but doesn’t define
the spaceship (<=>) operator?
Hint: It’s a descendant of Numeric.
Question 5:
Slide 20
Slide 20 text
Complex
Answer 5:
Slide 21
Slide 21 text
Thanks for playing!
Follow @sferik on Twitter for
more Ruby trivia and practica.