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

Ruby 2.5 What's New

Urabe Shyouhei
November 29, 2017

Ruby 2.5 What's New

Urabe Shyouhei

November 29, 2017
Tweet

More Decks by Urabe Shyouhei

Other Decks in Technology

Transcript

  1. Urabe, Shyouhei
    Ruby 2.5

    What’s New

    View full-size slide

  2. ·ͣ͸֓ܗ͔Β

    View full-size slide

  3. EJ⒎TUBUT
    ˠ 1585 files changed, 147854 insertions(+), 72571 deletions(-)
    ˠ 1549 files changed, 120363 insertions(+), 70385 deletions(-)
    ˠ 2933 files changed, 103658 insertions(+), 62082 deletions(-)
    ˠ 2263 files changed, 82556 insertions(+), 289978 deletions(-)
    ˠUSVOL 7061 files changed, 360060 insertions(+), 34025 deletions(-)

    View full-size slide

  4. bundler
    w ͍·ͷͱ͜Ζ͓ͦΒ͘࠷ޙͷඪ४ఴ෇ϥΠϒϥϦ
    w ͔Β͸ɺઃఆෆཁͰ͍͖ͳΓGemfileΛ ͋Ε
    ͹
    ಡΉΑ͏ʹͳΔ

    View full-size slide

  5. ଞϥΠϒϥϦ
    • Rubyspec
    • RDoc 6 (ripper integration)
    • ERb#result_with_hash
    • SecureRandom.alphanumeric
    • Binding#irb
    • etc.

    View full-size slide

  6. ERb#result_with_hash
    erb = ERb.new("<%= foo %>")
    erb.result_with_hash(foo: "1") # => "1"

    View full-size slide

  7. SecureRandom.alphanumeric
    SecureRandom.alphanumeric(32)
    # => "Xr3GCd3y2wkUgEF9lSh5pD2s5NDpeHSM"

    View full-size slide

  8. Binding#irb
    def foo
    while true do
    raise unless rand < 0.5
    end
    rescue
    binding.irb # <=
    end

    View full-size slide

  9. ίΞΫϥε
    • String#delete_prefix / String#delete_suffix
    • Array#append / Array#prepend
    • Dir#children / Dir#each_child
    • Hash#transform_keys
    • Kernel#yield_self

    View full-size slide

  10. String#delete_prefix
    "log.fluentd.message {...".delete_prefix("log.")
    # => "fluentd.message {..."

    View full-size slide

  11. Array#append
    %w'dolor sit amet'.prepend(%w'lorem ipsum')
    # => [["lorem", "ipsum"], "dolor", "sit", "amet"]
    %w'dolor sit amet'.prepend('lorem', 'ipsum')
    # => ["lorem", "ipsum", "dolor", "sit", "amet"]

    View full-size slide

  12. Hash#transform_keys
    {foo: 'bar'}.transform_keys(&:to_s)
    # => {"foo"=>"bar"}

    View full-size slide

  13. Kernel#yield_self
    {foo: 'bar'}.yield_self {|i| JSON.dump(i) }
    # => "{\"foo\":\"bar\"}"

    View full-size slide

  14. จ๏ͱ͔
    • do … rescue … end
    • Toplevel constant lookup removal
    • Reverse backtrace order

    View full-size slide

  15. do … rescue … end
    128.times do |i|
    raise unless rand < 0.5
    rescue RuntimeError
    puts $!
    end

    View full-size slide

  16. Reverse backtrace
    zsh % ruby -e 'def foo; bar; end' -e 'def bar; raise; end' -e 'foo'
    Traceback (most recent call last):
    2: from -e:3:in `'
    1: from -e:1:in `foo'
    -e:2:in `bar': unhandled exception
    [1] 34131 exit 1 ruby -e ‘…’
    zsh % ruby -e 'def foo; bar; end' -e 'def bar; raise; end' -e 'foo' 2>&1 | cat
    -e:2:in `bar': unhandled exception
    from -e:1:in `foo'
    from -e:3:in `'
    [1] 34291 exit 1 ruby -e ‘…’ 2>&1 |
    34292 done cat

    View full-size slide