Ruby 3.1 released: new features and performance improvements
Ruby is an object-oriented scripting language originally developed by Yukihiro Matsumoto (also known as Matz). The main website of the Ruby programming language is ruby-lang.org. Development began in February 1993 and the first alpha version of Ruby was released in December 1994. It was developed to be an alternative to scripting languages such as Perl and Python. Ruby borrows heavily from Perl and the class library is essentially an object-oriented reorganization of Perl’s functionality. Ruby also borrows from Lisp and Smalltalk. While Ruby does not borrow many features from Python, reading the code for Python helped Matz develop Ruby.
MacOS comes with Ruby already installed. Most Linux distributions either come with Ruby preinstalled or allow you to easily install Ruby from the distribution’s repository of free software. You can also download and install Ruby on Windows. The more technically adept can download the Ruby source code and compile it for most operating systems, including Unix, DOS, BeOS, OS/2, Windows, and Linux.
Feature
- Simple Syntax
- Normal Object-oriented Features (e.g. class, method calls)
- Advanced Object-oriented Features (e.g. mix-in, singleton-method)
- Operator Overloading
- Exception Handling
- Iterators and Closures
- Garbage Collection
- Dynamic Loading of Object Files (on some architectures)
- Highly Portable (works on many Unix-like/POSIX compatible platforms as well as Windows, macOS, Haiku, etc.) cf.
Changelog v3.1
Enumerator::Lazy
- Enumerator::Lazy#compact is added. [Feature #17312]
File
- File.dirname now accepts an optional argument for the level to strip path components. [Feature #12194]
GC
“GC.measure_total_time = true” enables the measurement of GC. Measurement can introduce overhead. It is enabled by default. GC.measure_total_time returns the current setting. GC.stat[:time] or GC.stat(:time) returns measured time in milli-seconds. [[Feature #10917]]
GC.total_time returns measured time in nano-seconds. [[Feature #10917]]
Integer
- Integer.try_convert is added. [Feature #15211]
Kernel
- Kernel#load now accepts a module as the second argument, and will load the file using the given module as the top-level module. [Feature #6210]
Marshal
- Marshal.load now accepts a
freeze: true
option. All returned objects are frozen except forClass
andModule
instances. Strings are deduplicated. [Feature #18148]MatchData
MatchData#match is added [Feature #18172]
MatchData#match_length is added [Feature #18172]
Method/UnboundMethod
- Method#public?, Method#private?, Method#protected?, UnboundMethod#public?, UnboundMethod#private?, UnboundMethod#protected? have been added. [Feature #11689]
Module
Module#prepend now modifies the ancestor chain if the receiver already includes the argument. Module#prepend still does not modify the ancestor chain if the receiver has already prepended the argument. [Bug #17423]
Module#private, #public, #protected, and #module_function will now return their arguments. If a single argument is given, it is returned. If no arguments are given, nil is returned. If multiple arguments are given, they are returned as an array. [Feature #12495]
Process
- Process._fork is added. This is a core method for fork(2). Do not call this method directly; it is called by existing fork methods: Kernel.#fork, Process.fork, and IO.popen(“-“). Application monitoring libraries can overwrite this method to hook fork events. [Feature #17795]
Struct
Passing only keyword arguments to Struct#initialize is warned. You need to use a Hash literal to set a Hash to a first member. [Feature #16806]
StructClass#keyword_init? is added [Feature #18008]
- More…