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

Ruby Quiz

pocke
October 08, 2017

Ruby Quiz

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

pocke

October 08, 2017
Tweet

More Decks by pocke

Other Decks in Programming

Transcript

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

    RuboCop' s core developer • Student at The Open University of Japan
  2. Ruby Quiz • You are a Ruby interpreter. ◦ You

    are a parse.y. ◦ You are a YARV. • You execute ruby code, and you output result.
  3. A. Why does it output "?"? p(??) p(%_?_) %<any character>…<any

    character> is a string literal. e.g.) %_?_ == "?" , %!???! == "???" ?_ is a character literal. e.g.) ?_ == "_" , ?? == "?"
  4. 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%", "")
  5. 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])
  6. • We can write tricky code in Ruby. ◦ Very

    fun!!! Thank you for listening! Conclusion