SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
New Features
in Ruby 2.4
Ireneusz Skrobiś
Lead Developer @ Selleo
New #sum method for Enumerable
New #sum method for Enumerable
[1, 1, 2, 3, 5, 8, 13, 21].sum # => 54
New #sum method for Enumerable
[1, 1, 2, 3, 5, 8, 13, 21].sum # => 54
The #sum method has an optional parameter which defaults to 0.
This value is the starting value of a summation meaning that [].sum is 0.
Faster Array#min and Array#max
Faster Array#min and Array#max
Array#min: 35.1 i/s
Enumerable#min: 21.8 i/s - 1.61x slower
Extract named captures from Regexp match results
Extract named captures from Regexp match results
pattern = /(?<first_name>John) (?<last_name>w+)/
pattern.match('John Backus').named_captures
# => {"first_name" => "John", "last_name" => "Backus"}
Extract named captures from Regexp match results
pattern = /(?<first_name>John) (?<last_name>w+)/
pattern.match('John Backus').named_captures
# => {"first_name" => "John", "last_name" => "Backus"}
pattern =
/(?<year>d{4})-(?<month>d{2})-(?<day>d{2})/
pattern.match('2016-02-01').values_at(:year, :month)
# => ["2016", "02"]
Faster regular expressions with Regexp#match?
Faster regular expressions with Regexp#match?
Regexp#match?: 2630002.5 i/s
Regexp#===: 872217.5 i/s - 3.02x slower
Regexp#=~: 859713.0 i/s - 3.06x slower
Regexp#match: 539361.3 i/s - 4.88x slower
New methods for testing if directories/files are empty
New methods for testing if directories/files are empty
Dir.empty?('empty_directory') # => true
Dir.empty?('directory_with_files') # => false
File.empty?('contains_text.txt') # => false
File.empty?('empty.txt') # => true
New Integer#digits method
New Integer#digits method
123.digits # => [3, 2, 1]
123.digits[0] # => 3
New Integer#digits method
123.digits # => [3, 2, 1]
123.digits[0] # => 3
# Equivalent behavior in Ruby 2.3:
123.to_s.chars.map(&:to_i).reverse # => [3, 2, 1]
Moves configuration to Logger’s constructor
Moves configuration to Logger’s constructor
logger = Logger.new(STDOUT, level: :info, progname: 'LOG')
Moves configuration to Logger’s constructor
logger = Logger.new(STDOUT, level: :info, progname: 'LOG')
# Equivalent behavior in Ruby 2.3:
logger = Logger.new(STDOUT)
logger.level = :info
logger.progname = 'LOG'
Simplified integers
Simplified integers
# Find classes which subclass the base "Numeric" class:
numerics = ObjectSpace.each_object(Module).select { |mod| mod < Numeric }
Simplified integers
# Find classes which subclass the base "Numeric" class:
numerics = ObjectSpace.each_object(Module).select { |mod| mod < Numeric }
# In Ruby 2.3:
numerics # => [Complex, Rational, Bignum, Float, Fixnum, Integer, BigDecimal]
Simplified integers
# Find classes which subclass the base "Numeric" class:
numerics = ObjectSpace.each_object(Module).select { |mod| mod < Numeric }
# In Ruby 2.3:
numerics # => [Complex, Rational, Bignum, Float, Fixnum, Integer, BigDecimal]
# In Ruby 2.4:
numerics # => [Complex, Rational, Float, Integer, BigDecimal]
New arguments supported for float modifiers
New arguments supported for float modifiers
4.55.ceil(1) # => 4.6
4.55.floor(1) # => 4.5
4.55.truncate(1) # => 4.5
4.55.round(1) # => 4.6
You can find more information here
https://blog.blockscore.com/new-features-in-ruby-2-4/
Thank you!
Live long and prosper :)
Ireneusz Skrobiś
Lead Developer @ Selleo

Weitere ähnliche Inhalte

Was ist angesagt? (20)

C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Merging tables using R
Merging tables using R Merging tables using R
Merging tables using R
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7
 
Windows power shell basics
Windows power shell basicsWindows power shell basics
Windows power shell basics
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
Perl one liners
Perl one linersPerl one liners
Perl one liners
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
PHP Mailer Remote Code Execution
PHP Mailer Remote Code ExecutionPHP Mailer Remote Code Execution
PHP Mailer Remote Code Execution
 
Itroroduction to R language
Itroroduction to R languageItroroduction to R language
Itroroduction to R language
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
11 15 (doubly linked list)
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Iteration
IterationIteration
Iteration
 
Linked list
Linked listLinked list
Linked list
 
Parallel arrays in python
Parallel arrays in pythonParallel arrays in python
Parallel arrays in python
 
Intro to ReactiveCocoa
Intro to ReactiveCocoaIntro to ReactiveCocoa
Intro to ReactiveCocoa
 

Ähnlich wie New features in Ruby 2.4

Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQIntro C# Book
 
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
RubyEnRails2007 - Dr Nic Williams - DIY SyntaxRubyEnRails2007 - Dr Nic Williams - DIY Syntax
RubyEnRails2007 - Dr Nic Williams - DIY SyntaxDr Nic Williams
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnArnaud Joly
 
R is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfR is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfannikasarees
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)BoneyGawande
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Introzhang tao
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbJuan Maiz
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionARVIND PANDE
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfoutcast96
 
Day 1c access, select ordering copy.pptx
Day 1c   access, select   ordering copy.pptxDay 1c   access, select   ordering copy.pptx
Day 1c access, select ordering copy.pptxAdrien Melquiond
 
PHP record- with all programs and output
PHP record- with all programs and outputPHP record- with all programs and output
PHP record- with all programs and outputKavithaK23
 

Ähnlich wie New features in Ruby 2.4 (20)

Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQ
 
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
RubyEnRails2007 - Dr Nic Williams - DIY SyntaxRubyEnRails2007 - Dr Nic Williams - DIY Syntax
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
R is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfR is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdf
 
R programming
R programmingR programming
R programming
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
DIWE - Advanced PHP Concepts
DIWE - Advanced PHP ConceptsDIWE - Advanced PHP Concepts
DIWE - Advanced PHP Concepts
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRb
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
Day 1c access, select ordering copy.pptx
Day 1c   access, select   ordering copy.pptxDay 1c   access, select   ordering copy.pptx
Day 1c access, select ordering copy.pptx
 
PHP record- with all programs and output
PHP record- with all programs and outputPHP record- with all programs and output
PHP record- with all programs and output
 

Mehr von Ireneusz Skrobiś

Bugs and non-technical client
Bugs and non-technical clientBugs and non-technical client
Bugs and non-technical clientIreneusz Skrobiś
 
PayPal Subscriptions in Ruby on Rails application
PayPal Subscriptions in Ruby on Rails applicationPayPal Subscriptions in Ruby on Rails application
PayPal Subscriptions in Ruby on Rails applicationIreneusz Skrobiś
 
How to introduce a new developer to a project.
How to introduce a new developer to a project.How to introduce a new developer to a project.
How to introduce a new developer to a project.Ireneusz Skrobiś
 
Geolocation Databases in Ruby on Rails
Geolocation Databases in Ruby on RailsGeolocation Databases in Ruby on Rails
Geolocation Databases in Ruby on RailsIreneusz Skrobiś
 
Geocoding with Rails and Twitter Typeahead
Geocoding with Rails and Twitter TypeaheadGeocoding with Rails and Twitter Typeahead
Geocoding with Rails and Twitter TypeaheadIreneusz Skrobiś
 
LOL vs Dota2: Battle Of APIs
LOL vs Dota2: Battle Of APIsLOL vs Dota2: Battle Of APIs
LOL vs Dota2: Battle Of APIsIreneusz Skrobiś
 
What to do when there is no API
What to do when there is no APIWhat to do when there is no API
What to do when there is no APIIreneusz Skrobiś
 

Mehr von Ireneusz Skrobiś (8)

Bugs and non-technical client
Bugs and non-technical clientBugs and non-technical client
Bugs and non-technical client
 
PayPal Subscriptions in Ruby on Rails application
PayPal Subscriptions in Ruby on Rails applicationPayPal Subscriptions in Ruby on Rails application
PayPal Subscriptions in Ruby on Rails application
 
New features in Ruby 2.5
New features in Ruby 2.5New features in Ruby 2.5
New features in Ruby 2.5
 
How to introduce a new developer to a project.
How to introduce a new developer to a project.How to introduce a new developer to a project.
How to introduce a new developer to a project.
 
Geolocation Databases in Ruby on Rails
Geolocation Databases in Ruby on RailsGeolocation Databases in Ruby on Rails
Geolocation Databases in Ruby on Rails
 
Geocoding with Rails and Twitter Typeahead
Geocoding with Rails and Twitter TypeaheadGeocoding with Rails and Twitter Typeahead
Geocoding with Rails and Twitter Typeahead
 
LOL vs Dota2: Battle Of APIs
LOL vs Dota2: Battle Of APIsLOL vs Dota2: Battle Of APIs
LOL vs Dota2: Battle Of APIs
 
What to do when there is no API
What to do when there is no APIWhat to do when there is no API
What to do when there is no API
 

Kürzlich hochgeladen

System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosVictor Morales
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
signals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsignals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsapna80328
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdfsahilsajad201
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
Ch10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfCh10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfChristianCDAM
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHSneha Padhiar
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESkarthi keyan
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfDrew Moseley
 
Turn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxTurn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxStephen Sitton
 
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmComputer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmDeepika Walanjkar
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfBalamuruganV28
 

Kürzlich hochgeladen (20)

System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitos
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
signals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsignals in triangulation .. ...Surveying
signals in triangulation .. ...Surveying
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdf
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
Ch10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfCh10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdf
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdf
 
Turn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxTurn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptx
 
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmComputer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
 

New features in Ruby 2.4

  • 1. New Features in Ruby 2.4 Ireneusz Skrobiś Lead Developer @ Selleo
  • 2. New #sum method for Enumerable
  • 3. New #sum method for Enumerable [1, 1, 2, 3, 5, 8, 13, 21].sum # => 54
  • 4. New #sum method for Enumerable [1, 1, 2, 3, 5, 8, 13, 21].sum # => 54 The #sum method has an optional parameter which defaults to 0. This value is the starting value of a summation meaning that [].sum is 0.
  • 6. Faster Array#min and Array#max Array#min: 35.1 i/s Enumerable#min: 21.8 i/s - 1.61x slower
  • 7. Extract named captures from Regexp match results
  • 8. Extract named captures from Regexp match results pattern = /(?<first_name>John) (?<last_name>w+)/ pattern.match('John Backus').named_captures # => {"first_name" => "John", "last_name" => "Backus"}
  • 9. Extract named captures from Regexp match results pattern = /(?<first_name>John) (?<last_name>w+)/ pattern.match('John Backus').named_captures # => {"first_name" => "John", "last_name" => "Backus"} pattern = /(?<year>d{4})-(?<month>d{2})-(?<day>d{2})/ pattern.match('2016-02-01').values_at(:year, :month) # => ["2016", "02"]
  • 10. Faster regular expressions with Regexp#match?
  • 11. Faster regular expressions with Regexp#match? Regexp#match?: 2630002.5 i/s Regexp#===: 872217.5 i/s - 3.02x slower Regexp#=~: 859713.0 i/s - 3.06x slower Regexp#match: 539361.3 i/s - 4.88x slower
  • 12. New methods for testing if directories/files are empty
  • 13. New methods for testing if directories/files are empty Dir.empty?('empty_directory') # => true Dir.empty?('directory_with_files') # => false File.empty?('contains_text.txt') # => false File.empty?('empty.txt') # => true
  • 15. New Integer#digits method 123.digits # => [3, 2, 1] 123.digits[0] # => 3
  • 16. New Integer#digits method 123.digits # => [3, 2, 1] 123.digits[0] # => 3 # Equivalent behavior in Ruby 2.3: 123.to_s.chars.map(&:to_i).reverse # => [3, 2, 1]
  • 17. Moves configuration to Logger’s constructor
  • 18. Moves configuration to Logger’s constructor logger = Logger.new(STDOUT, level: :info, progname: 'LOG')
  • 19. Moves configuration to Logger’s constructor logger = Logger.new(STDOUT, level: :info, progname: 'LOG') # Equivalent behavior in Ruby 2.3: logger = Logger.new(STDOUT) logger.level = :info logger.progname = 'LOG'
  • 21. Simplified integers # Find classes which subclass the base "Numeric" class: numerics = ObjectSpace.each_object(Module).select { |mod| mod < Numeric }
  • 22. Simplified integers # Find classes which subclass the base "Numeric" class: numerics = ObjectSpace.each_object(Module).select { |mod| mod < Numeric } # In Ruby 2.3: numerics # => [Complex, Rational, Bignum, Float, Fixnum, Integer, BigDecimal]
  • 23. Simplified integers # Find classes which subclass the base "Numeric" class: numerics = ObjectSpace.each_object(Module).select { |mod| mod < Numeric } # In Ruby 2.3: numerics # => [Complex, Rational, Bignum, Float, Fixnum, Integer, BigDecimal] # In Ruby 2.4: numerics # => [Complex, Rational, Float, Integer, BigDecimal]
  • 24. New arguments supported for float modifiers
  • 25. New arguments supported for float modifiers 4.55.ceil(1) # => 4.6 4.55.floor(1) # => 4.5 4.55.truncate(1) # => 4.5 4.55.round(1) # => 4.6
  • 26. You can find more information here https://blog.blockscore.com/new-features-in-ruby-2-4/
  • 27. Thank you! Live long and prosper :) Ireneusz Skrobiś Lead Developer @ Selleo