Numbers

Fixnum and Bignum have been unified into Integer class.

So far, we’ve had two classes for storing integers -
Fixnum for small integers, and Bignum for numbers outside this range.
However, these are implementation details
that programmers don’t need to worry about while writing code.

These two classes have been replaced by a single Integer class.
Previously, Integer was a superclass of these two classes,
but now both Fixnum and Bignum are aliases to Integer.

Float methods like #ceil, #floor, #truncate and #round
take an optional argument to set precision.

1.567.round#=> 21.567.round(2)#=> 1.57123.456.round(-1)#=> 120

Float#round default behavior remains unchanged

This one isn’t really a change,
but this change in default behavior initially made it to one of the preview releases,
and was reverted later on.

By default, #round uses round-half-up behavior, ie. 1.5 would be rounded to 2.
The new behavior was to use banker’s rounding, which rounds half to nearest even number.
This might cause bugs in many existing applications which rely on half-up rounding,
so the original default has been retained.

binding.irb

I’m a big fan of the pry gem for the binding.pry method
that opens a REPL while running your code.
IRB has now introduced this feature,
and ruby now opens a REPL when it encounters the binding.irb method.

Hash

Hash#compact

This method, and the bang version, #compact!,
remove keys with nil values from the hash.

{a: "foo",b: false,c: nil}.compact#=> { a: "foo", b: false }

Hash#transform_values

Applies the block for each value in the hash.
Also provides a #transform_values! method that modifies the existing hash.
Examples from the docs:

Language features

Multiple assignment in conditionals

In Ruby 2.3, you would get a syntax error
if you tried multiple assignment in a conditional.
This has been changed to a warning instead.

# 2.3if(a,b=[1,2])then'yes'else'no'end#=> SyntaxError: (irb):9: multiple assignment in conditional# 2.4if(a,b=[1,2])then'yes'else'no'end#=> warning: found = in conditional, should be ==#=> 'yes'if(a,b=nil)then'yes'else'no'end#=> warning: found = in conditional, should be ==#=> 'no'

Wrapping up

I haven’t mentioned all the new features in Ruby 2.4 here,
but if you’re interested in the complete list of changes, take a look at the
Ruby 2.4.0 NEWS file.

Hi, I’m Nithin Bekal.
I work at Shopify in Ottawa, Canada.
Previously, co-founder of
CrowdStudio.in and
WowMakers.
Ruby is my preferred programming language,
and the topic of most of my articles here,
but I'm also a big fan of Elixir.
Tweet to me at @nithinbekal.