Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby Trivia

Ruby Trivia

Presented at the Berlin Ruby User Group (RUG::B) on October 1, 2015.

1f74b13f1e5c6c69cb5d7fbaabb1e2cb?s=128

Erik Berlin

October 01, 2015
Tweet

Transcript

  1. Ruby Trivia

  2. 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:
  3. 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:
  4. $- Answer 1:

  5. Why can’t variable names contain dashes? Bonus Question:

  6. 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).
  7. Ruby may define a special File object in the first

    file it interprets. What is it called? What does it do? Question 2:
  8. 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__
  9. DATA Answer 2:

  10. What happens if you call: DATA.rewind before DATA.read Bonus Question:

  11. What happens if you call: DATA.rewind before DATA.read Bonus Question:

    Answer: It reads the entire file, including the source code.
  12. 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:
  13. void value expression Answer 3:

  14. 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:
  15. [] Answer 4:

  16. What method would need to be added to the Range

    interface to make descending sequences possible? Bonus Question:
  17. What method would need to be added to the Range

    interface to make descending sequences possible? Bonus Question: Answer: pred (the opposite of succ).
  18. What Ruby class mixes-in Comparable but doesn’t define the spaceship

    (<=>) operator? Question 5:
  19. What Ruby class mixes-in Comparable but doesn’t define the spaceship

    (<=>) operator? Hint: It’s a descendant of Numeric. Question 5:
  20. Complex Answer 5:

  21. Thanks for playing! Follow @sferik on Twitter for more Ruby

    trivia and practica.