A very interesting feature was proposed to be added to Ruby. If you can imagine from the title - Yes! endless Ruby. But in what context? Let's see in this blog post.
Method definition in Ruby is done this way :
def some_method
# one-line method body
end
The proposal is to allow the below syntax for method definitions
def value(args) = expression
You see, there is no end keyword hence endless.
This just applies to method definitions.
With this in place, the below examples can be considered
def hello(name) =
puts "Hello #{name}!"
hello('endless Ruby') #=> Hello endless Ruby!
and
def square(x) = x * x
p square(4) #=> 16
and
x = Object.new
def x.foo = "FOO"
p x.foo #=> "FOO"
I felt it would a nice thing to add, as we often write one-line methods.
Discussions on this proposal are happening here. Feel free to visit and express your thoughts.
Top comments (0)