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

Ruby 2.7 - Beyond the CHANGELOG

Ruby 2.7 - Beyond the CHANGELOG

Let's go beyond the CHANGELOG and answer the important questions. In this talk I will give you some insights what ruby 2.7 is about, what kinds of problems you are going to find ahead and answer the ultimate question: Is it worth upgrading?

Gabriel Mazetto

January 14, 2020
Tweet

More Decks by Gabriel Mazetto

Other Decks in Programming

Transcript

  1. 1

  2. 3

  3. 4

  4. 5

  5. 6

  6. 7

  7. 8

  8. 9

  9. 10

  10. 11

  11. 13

  12. irb(main):001:0> [1,2,3] in [a,b,c] (irb):1: warning: Pattern matching is experimental,

    and the behavior may change in future versions of Ruby! => nil irb(main):002:0> c => 3 17
  13. 18

  14. 19

  15. 21

  16. def something(args = {}) # ... end args = {a:

    1, b: 2} something(args) 22
  17. def something(a:, b:) # ... end args = {a: 1,

    b: 2} something(args) warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call warning: The called method `something' is defined here 24
  18. def something(a:, b:) # ... end args = {a: 1,

    b: 2} something( **args) 25
  19. def something( **args) # args => {a: 1, b: 2}

    end something(a: 1, b: 2) 27
  20. def something(a:, b:) # a = 1 # b =

    2 end args = {a: 1, b: 2} something( **args) 28
  21. def something(a, b, c) # a = 1 # b

    = 2 # c = 3 end args = [1,2,3] something(*args) 30
  22. 33

  23. 34

  24. 35

  25. 37

  26. 38 # Ruby <= 2.6 10.times { |value| puts value

    } # Ruby 2.7 10.times { puts _1 }
  27. 39

  28. # Ruby 2.7 el = %W(a b c d e

    f a b a b c d a b) el.tally # => {"a" =>4, "b" =>4, "c" =>2, "d" =>2, "e" =>1, "f" =>1} 40
  29. # Ruby <= 2.6 V2 el.group_by { |v| v }.map

    { |k, v| [k, v.size] }.to_h 42
  30. 45

  31. 47

  32. enum = 1.upto(1_000) enum.filter_map { |i| i + 1 if

    i.even? } # => [3, 5, 7, 9, 11, 13, ...] 48
  33. 49

  34. 53

  35. 59