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

Ruby Quiz

7bc6612fa20296bf652f6b0357db81c1?s=47 pocke
October 08, 2017

Ruby Quiz

at 学生エンジニア限定LT大会

7bc6612fa20296bf652f6b0357db81c1?s=128

pocke

October 08, 2017
Tweet

Transcript

  1. Ruby Quiz Oct. 8, 2017 第4回 学生エンジニア限定LT大会

  2. I have only 5 minutes, so I'll speak very fast.

  3. Self introduction • Pocke • Actcat, Inc. / SideCI •

    RuboCop' s core developer • Student at The Open University of Japan
  4. SideCI

  5. Automated Code Review as a Service

  6. Please access here! https://sideci.com

  7. Ruby Quiz

  8. Question

  9. Do you write Ruby?

  10. Ruby Quiz • You are a Ruby interpreter. ◦ You

    are a parse.y. ◦ You are a YARV. • You execute ruby code, and you output result.
  11. Quiz 1

  12. Q. What does the code output? p(??) p(%_?_)

  13. Answer p(??) # => "?" p(%_?_) # => "?"

  14. Why?

  15. A. Why does it output "?"? p(??) p(%_?_) %<any character>…<any

    character> is a string literal. e.g.) %_?_ == "?" , %!???! == "???" ?_ is a character literal. e.g.) ?_ == "_" , ?? == "?"
  16. Quiz 2

  17. Q. What does the code output? p(????::?:) p(% %s% %%%%)

  18. Answer p(????::?:) # => ":" p(% %s% %%%%) # =>

    "%"
  19. Why????

  20. Answer p(????::?:) p(% %s% %%%%) 1. ?? is "?" 2.

    ? is a part of conditional op 3. ?: is ":" 4. : is a part of conditional op 5. ?: is ":" "?" ? ":" : ":" 1. % %s% is "%s%" 2. % is a format op(Like sprintf) 3. %%% is "" sprintf("%s%", "")
  21. Quiz 3

  22. Q. What does the code output? a = ["1","2","3"] a&.map(&:to_i)&.&([1])

  23. Answer a = ["1","2","3"] a&.map(&:to_i)&.&([1]) # => [1]

  24. Why?????

  25. Answer a = ["1","2","3"] a&.map(&:to_i)&.&([1]) # => [1] &. is

    a safe navigation op(nil guard). &:to_i is an implicit to_proc op. A safe navigation op & is an intersection op call (like [1,2,3] & [1])
  26. Conclusion

  27. • We can write tricky code in Ruby. ◦ Very

    fun!!! Thank you for listening! Conclusion