iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💎

Ruby 3.2 - Removed Classes and Constants

に公開

This is the article for day 4 of the Ruby 3.2 Advent Calendar.

https://qiita.com/advent-calendar/2022/ruby32


Removed Classes and Constants

Fixnum / Bignum

Feature #12005: Unify Fixnum and Bignum into Integer - Ruby master - Ruby Issue Tracking System

Since Ruby 2.4, Fixnum and Bignum have been deprecated and became aliases for Integer.

Warning[:deprecated] = true
Fixnum  #=> Integer
#=> warning: constant ::Fixnum is deprecated
Bignum  #=> Integer
#=> warning: constant ::Bignum is deprecated

They have finally been removed in Ruby 3.2.

Fixnum
#=> uninitialized constant Fixnum (NameError)
Bignum
#=> uninitialized constant Bignum (NameError)

It took a long time until they were gone...

Random::DEFAULT

Up until Ruby 2.7, Random::DEFAULT returned a Random object representing the default random number generator (I'm not entirely sure about the details), but since it wasn't thread-safe, Random::DEFAULT was deprecated in Ruby 3.0 and started returning the Random class itself.

Warning[:deprecated] = true
Random::DEFAULT  #=> Random
#=> warning: constant Random::DEFAULT is deprecated

It has been removed in Ruby 3.2.

Random::DEFAULT
#=> uninitialized constant Random::DEFAULT (NameError)

Struct::Group / Struct::Passwd

When you called require 'etc', for some reason Struct::Group and Struct::Passwd were created, although they were actually Etc::Group and Etc::Passwd.

They have been deprecated since Ruby 3.0.

Warning[:deprecated] = true
require 'etc'
Struct::Group   #=> Etc::Group
#=> warning: constant Struct::Group is deprecated
Struct::Passwd  #=> Etc::Passwd
#=> warning: constant Struct::Passwd is deprecated

They have been removed in Ruby 3.2.

require 'etc'
Struct::Group   #=> Etc::Group
#=> uninitialized constant Struct::Group (NameError)
Struct::Passwd  #=> Etc::Passwd
#=> uninitialized constant Struct::Passwd (NameError)

By the way, I wonder why they existed under Struct in the first place.

Discussion