RUBY 2.5
IRENEUSZ SKROBIŚ
Lead developer @ SELLEO
AGENDA
AGENDA
new features
AGENDA
new features
performance
improvements
AGENDA
new features
performance
improvements
other notable
changes
New features
1
rescue/else/ensure are now allowed
to be used directly with do/end blocks
AFTER:
lambda do
raise 'err'
rescue
$! # => #<RuntimeError: err>
end.call
BEFORE:
lambda do
begin
raise 'err'
rescue
$! # => #<RuntimeError: err>
end
end.call
Add yield_self to yield given block in its context
class Object
def yield_self(*args)
yield(self, *args)
end
end
2.yield_self { |x| x*x } # => 4
Hash#slice & Hash#except
{ a: 1, b: 2, c: 3, d: 4 }.slice(:a, :b)
# => { a: 1, b: 2 }
{ a: 1, b: 2, c: 3, d: 4 }.except(:a, :b)
# => { c: 3, d: 4 }
Hash#transform_keys
{ a: 1, b: 2 }.transform_keys { |k| k.to_s }
=> { "a"=>1, "b"=>2 }
Struct.new can create classes that accept keyword arguments
Point = Struct.new(:x, :y, :color)
point1 = Point.create(x: 1, y: 2)
# => Point<x: 1, y: 2, color: nil>
point2 = Point.create!(x: 1, y: 2)
# => ArgumentError, color not specified.
Enumerable#any?, all?, none?, and one? accept a pattern argument
[1, 3.14, 2ri].all?(Numeric) # => true
if should_be_all_symbols.any?(String)
...
end
some_strings.none?(/aeiou/i)
Array#prepend/append as aliases of unshift/push
array = [3, 4]
array.prepend(1, 2) #=> [1, 2, 3, 4]
array #=> [1, 2, 3, 4]
array = [1, 2]
array.append(3, 4) #=> [1, 2, 3, 4]
array #=> [1, 2, 3, 4]
Top-level constant look-up is no longer available
# this is removed:
irb(main):001:0> class Auth; end
=> nil
irb(main):002:0> class Twitter; end
=> nil
irb(main):003:0> Twitter::Auth
(irb):3: warning: toplevel constant Auth referenced by Twitter::Auth
=> Auth
Print backtrace and error message in reverse order
AFTER:
stack frame 3
stack frame 2
stack frame 1
Main Error Message
.....
BEFORE:
Main Error Message
stack frame 1
stack frame 2
stack frame 3
.....
Performance improvements
2
Performance improvements
◉ About 5-10% performance improvement by removing all
trace instructions from overall bytecode (instruction
sequences)
Performance improvements
◉ About 5-10% performance improvement by removing all
trace instructions from overall bytecode (instruction
sequences)
◉ Block passing by a block parameter
(e.g. def foo(&b); bar(&b); end)
is about 3 times faster than Ruby 2.4
Performance improvements
◉ About 5-10% performance improvement by removing all
trace instructions from overall bytecode (instruction
sequences)
◉ Block passing by a block parameter
(e.g. def foo(&b); bar(&b); end)
is about 3 times faster than Ruby 2.4
◉ ERB now generates code from a template twice as fast as
Ruby 2.4
Performance improvements
◉ About 5-10% performance improvement by removing all
trace instructions from overall bytecode (instruction
sequences)
◉ Block passing by a block parameter
(e.g. def foo(&b); bar(&b); end)
is about 3 times faster than Ruby 2.4
◉ ERB now generates code from a template twice as fast as
Ruby 2.4
◉ (and more…)
Other notable changes
3
Other notable changes
◉ Thread.report_on_exception is now set to true by default.
Other notable changes
◉ Thread.report_on_exception is now set to true by default.
◉ SecureRandom now prefers OS-provided sources over
OpenSSL
Other notable changes
◉ Thread.report_on_exception is now set to true by default.
◉ SecureRandom now prefers OS-provided sources over
OpenSSL
◉ Promote cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils,
gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib
from standard libraries to default gems.
Other notable changes
◉ Thread.report_on_exception is now set to true by default.
◉ SecureRandom now prefers OS-provided sources over
OpenSSL
◉ Promote cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils,
gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib
from standard libraries to default gems.
◉ Update supported Unicode version to 10.0.0.
Other notable changes
◉ Thread.report_on_exception is now set to true by default.
◉ SecureRandom now prefers OS-provided sources over
OpenSSL
◉ Promote cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils,
gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib
from standard libraries to default gems.
◉ Update supported Unicode version to 10.0.0.
◉ Update to RubyGems 2.7.3, RDoc 6.0.1.
Other notable changes
◉ Thread.report_on_exception is now set to true by default.
◉ SecureRandom now prefers OS-provided sources over
OpenSSL
◉ Promote cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils,
gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib
from standard libraries to default gems.
◉ Update supported Unicode version to 10.0.0.
◉ Update to RubyGems 2.7.3, RDoc 6.0.1.
◉ (and more…)
SUMMARY
new features
performance
improvements
other notable
changes
THANKS!
Live long and prosper :)
Ireneusz Skrobiś
@ireneuszskrobis

New features in Ruby 2.5

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
    rescue/else/ensure are nowallowed to be used directly with do/end blocks AFTER: lambda do raise 'err' rescue $! # => #<RuntimeError: err> end.call BEFORE: lambda do begin raise 'err' rescue $! # => #<RuntimeError: err> end end.call
  • 8.
    Add yield_self toyield given block in its context class Object def yield_self(*args) yield(self, *args) end end 2.yield_self { |x| x*x } # => 4
  • 9.
    Hash#slice & Hash#except {a: 1, b: 2, c: 3, d: 4 }.slice(:a, :b) # => { a: 1, b: 2 } { a: 1, b: 2, c: 3, d: 4 }.except(:a, :b) # => { c: 3, d: 4 }
  • 10.
    Hash#transform_keys { a: 1,b: 2 }.transform_keys { |k| k.to_s } => { "a"=>1, "b"=>2 }
  • 11.
    Struct.new can createclasses that accept keyword arguments Point = Struct.new(:x, :y, :color) point1 = Point.create(x: 1, y: 2) # => Point<x: 1, y: 2, color: nil> point2 = Point.create!(x: 1, y: 2) # => ArgumentError, color not specified.
  • 12.
    Enumerable#any?, all?, none?,and one? accept a pattern argument [1, 3.14, 2ri].all?(Numeric) # => true if should_be_all_symbols.any?(String) ... end some_strings.none?(/aeiou/i)
  • 13.
    Array#prepend/append as aliasesof unshift/push array = [3, 4] array.prepend(1, 2) #=> [1, 2, 3, 4] array #=> [1, 2, 3, 4] array = [1, 2] array.append(3, 4) #=> [1, 2, 3, 4] array #=> [1, 2, 3, 4]
  • 14.
    Top-level constant look-upis no longer available # this is removed: irb(main):001:0> class Auth; end => nil irb(main):002:0> class Twitter; end => nil irb(main):003:0> Twitter::Auth (irb):3: warning: toplevel constant Auth referenced by Twitter::Auth => Auth
  • 15.
    Print backtrace anderror message in reverse order AFTER: stack frame 3 stack frame 2 stack frame 1 Main Error Message ..... BEFORE: Main Error Message stack frame 1 stack frame 2 stack frame 3 .....
  • 16.
  • 17.
    Performance improvements ◉ About5-10% performance improvement by removing all trace instructions from overall bytecode (instruction sequences)
  • 18.
    Performance improvements ◉ About5-10% performance improvement by removing all trace instructions from overall bytecode (instruction sequences) ◉ Block passing by a block parameter (e.g. def foo(&b); bar(&b); end) is about 3 times faster than Ruby 2.4
  • 19.
    Performance improvements ◉ About5-10% performance improvement by removing all trace instructions from overall bytecode (instruction sequences) ◉ Block passing by a block parameter (e.g. def foo(&b); bar(&b); end) is about 3 times faster than Ruby 2.4 ◉ ERB now generates code from a template twice as fast as Ruby 2.4
  • 20.
    Performance improvements ◉ About5-10% performance improvement by removing all trace instructions from overall bytecode (instruction sequences) ◉ Block passing by a block parameter (e.g. def foo(&b); bar(&b); end) is about 3 times faster than Ruby 2.4 ◉ ERB now generates code from a template twice as fast as Ruby 2.4 ◉ (and more…)
  • 21.
  • 22.
    Other notable changes ◉Thread.report_on_exception is now set to true by default.
  • 23.
    Other notable changes ◉Thread.report_on_exception is now set to true by default. ◉ SecureRandom now prefers OS-provided sources over OpenSSL
  • 24.
    Other notable changes ◉Thread.report_on_exception is now set to true by default. ◉ SecureRandom now prefers OS-provided sources over OpenSSL ◉ Promote cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils, gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib from standard libraries to default gems.
  • 25.
    Other notable changes ◉Thread.report_on_exception is now set to true by default. ◉ SecureRandom now prefers OS-provided sources over OpenSSL ◉ Promote cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils, gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib from standard libraries to default gems. ◉ Update supported Unicode version to 10.0.0.
  • 26.
    Other notable changes ◉Thread.report_on_exception is now set to true by default. ◉ SecureRandom now prefers OS-provided sources over OpenSSL ◉ Promote cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils, gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib from standard libraries to default gems. ◉ Update supported Unicode version to 10.0.0. ◉ Update to RubyGems 2.7.3, RDoc 6.0.1.
  • 27.
    Other notable changes ◉Thread.report_on_exception is now set to true by default. ◉ SecureRandom now prefers OS-provided sources over OpenSSL ◉ Promote cmath, csv, date, dbm, etc, fcntl, fiddle, fileutils, gdbm, ipaddr, scanf, sdbm, stringio, strscan, webrick, zlib from standard libraries to default gems. ◉ Update supported Unicode version to 10.0.0. ◉ Update to RubyGems 2.7.3, RDoc 6.0.1. ◉ (and more…)
  • 28.
  • 29.
    THANKS! Live long andprosper :) Ireneusz Skrobiś @ireneuszskrobis