Today I Learned

hashrocket A Hashrocket project

Endless Method Definition in Ruby

A new method definition was introduced in Ruby 3.0, the endless definition.

You're probably familiar with:

def do_something(number)
  number * 2
end

Of course, we can express this as a one-liner previously as:

def do_something(number); number * 2; end

Now you have the option to write it like this:

def do_something(number) = number * 2

Or another example:

def thing(x) = @thing = x

If you'd like to know more, here is where the spec was discussed

See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.