Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Self introduction ● Pocke ● Actcat, Inc. / SideCI ● RuboCop' s core developer ● Student at The Open University of Japan

Slide 4

Slide 4 text

SideCI

Slide 5

Slide 5 text

Automated Code Review as a Service

Slide 6

Slide 6 text

Please access here! https://sideci.com

Slide 7

Slide 7 text

Ruby Quiz

Slide 8

Slide 8 text

Question

Slide 9

Slide 9 text

Do you write Ruby?

Slide 10

Slide 10 text

Ruby Quiz ● You are a Ruby interpreter. ○ You are a parse.y. ○ You are a YARV. ● You execute ruby code, and you output result.

Slide 11

Slide 11 text

Quiz 1

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Why?

Slide 15

Slide 15 text

A. Why does it output "?"? p(??) p(%_?_) %… is a string literal. e.g.) %_?_ == "?" , %!???! == "???" ?_ is a character literal. e.g.) ?_ == "_" , ?? == "?"

Slide 16

Slide 16 text

Quiz 2

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Why????

Slide 20

Slide 20 text

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%", "")

Slide 21

Slide 21 text

Quiz 3

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Why?????

Slide 25

Slide 25 text

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])

Slide 26

Slide 26 text

Conclusion

Slide 27

Slide 27 text

● We can write tricky code in Ruby. ○ Very fun!!! Thank you for listening! Conclusion