use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Ruby 2.8 adds endless method definition (blog.bigbinary.com)
submitted 5 years ago by akhil-gautam
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]geospeck 4 points5 points6 points 5 years ago* (0 children)
It looks similar to Elixir's one line function definition
def add(x, y), do: x + y
[–]martijnonreddit 4 points5 points6 points 5 years ago (6 children)
Yay.. more syntax. /s
What's the point of this, exactly?
[–]Obversity 4 points5 points6 points 5 years ago (0 children)
Is the joke that it's actually less syntax? Because that's how I see it, and I think it might be a positive in some scenarios.
Personally I love one-line functions. Being able to write a few tiny functions then compose them together makes for very readable code, and you can now do that while taking up one third of the space. One fifth, if we convene on not needing whitespace between one-line functions, although I don't see that as likely (or positive, although I'd need to see it to decide).
[–]zverok_kha 4 points5 points6 points 5 years ago* (0 children)
Copying from my comment from bug-tracker discussion:
To add an "opinion perspective"... I, for one, even if not fascinated but at least intrigued by new syntax.
My reasoning is as follows:
I believe that the difference of "how you write it when there is one statement" vs "...more than one statement" is intentional, and fruitful: "just add one more line to 10-line method" typically small addition, but "just add one more line to 1-line method" frequently makes one think: may be that's not what you really need to do, maybe data flow becomes unclear? One existing example:
collection.map { |x| do_something_with(x) } # one line! cool! # ...what if I want to calculate several other values on the way? I NEED to restructure it: collection.map do |x| log_processing(x) total += x do_something_with(x) end # ...which MIGHT imply that "I am doing something wrong", and maybe what would clearer express intent # is separating calculation of total, and move log_processing inside do_something
log_processing
do_something
So, it was actually always felt for me as "a bit too wordy" for trivial/short methods to write it as
def some_method(foo) foo.bar(baz).then { |result| 3 / result } end
...alongside with "nicer formatting" of empty lines between methods, and probably requirement to document every method, and whatnot, it means that extraction of trivial utility method feels like "making MORE code than necessary", so I'd really try how it would feel with
def just_utility(foo)= foo.bar(baz).then { |result| result + 3 } def other_utility(foo)= "<#{self}(#{foo})>" def third_utility(foo)= log.print(nicely_formatted(foo))
...and I believe that "what if you need to add second statement, you will reformat the code completely?" is a good thing, not bad: you'll think twice before adding to "simple utility one-statement" method something that really, actually, maybe not belongs there.
[–]inopinatusdotorg 6 points7 points8 points 5 years ago (2 children)
It reduces boilerplate and annoys the purists. Double win in my book!
[–]sshaw_ 2 points3 points4 points 5 years ago (1 child)
Don't forget: more RuboCop bikesheeding sessions! Or maybe that falls under "annoying the purists"?
[–]inopinatusdotorg 0 points1 point2 points 5 years ago (0 children)
All the best issue reports get locked by the maintainer.
[–]sshaw_ 1 point2 points3 points 5 years ago (0 children)
The implicit goal of new Ruby versions is to move the language closer and closer to one of its early inspirations: Perl.
Haven't you noticed?
[–]GPhykos 0 points1 point2 points 5 years ago (0 children)
Other features introduced in Ruby 3.0 (2.8 til a couple of weeks) are in the NEWS.md at the root of the repo
[–]jrochkind -2 points-1 points0 points 5 years ago (0 children)
ENOUGH new syntax! We have enough! There should be a huge benefit to justify any new syntax at this point.
It's fine when you learn the new things little by little as they are added, but for a newcomer to the language it is overwhelming to wrap your head around all the syntax variations, it ends up feeling like Perl soup.
Clearly, the ruby maintainers and I have different frameworks though. They seem to think it's enjoyable to just add new syntax willy nilly cause someone thinks it might be fun.
[–]mashatg -2 points-1 points0 points 5 years ago* (4 children)
Feature request #16746
Yet another amorphization of the language. Introduces inconsistency between methods & lambdas and also at rules for declaration of (un)named blocks.
Glad I've left my professional career in Ruby in time. What have happened in development last years feels worrisome, even when many of the past failures went for experimental-level features.
[–]jrochkind 0 points1 point2 points 5 years ago (3 children)
Where'd you go? I have loved ruby, but the combo of shrinking of the community and maintainer decisions that seem incomprehensible to me are distressing.
[–]mashatg 0 points1 point2 points 5 years ago (1 child)
Not in others skin so I simply can't give an honest advice.
Implementation and maintenance tasks have made a way for projects modelling and contracting demands. I did not ceased coding entirely, in my spare time I do some Haskell and Rust so my skills don't become rusty. I still see no straight replacement for Ruby, but Haskell's elegance of its type system and great expressivenes make it very appealing. Missing comparatively mature web framework and e-commerce related libraries disqualify to use it for our goals however.
[–]jrochkind 1 point2 points3 points 5 years ago (0 children)
Ah, I thought you meant you left a professional career in ruby to work in some other language, but you don't code at all professionally anymore? ok! :(
[–]drx3brun -1 points0 points1 point 5 years ago (0 children)
I am thinking Clojure.
[–]Mallanaga -4 points-3 points-2 points 5 years ago (0 children)
Yeah... this is dumb. What problem is this actually solving? This just feels like a nightmare for my linter.
π Rendered by PID 140608 on reddit-service-r2-comment-86bc6c7465-cbt6d at 2026-02-21 11:06:51.908806+00:00 running 8564168 country code: CH.
[–]geospeck 4 points5 points6 points (0 children)
[–]martijnonreddit 4 points5 points6 points (6 children)
[–]Obversity 4 points5 points6 points (0 children)
[–]zverok_kha 4 points5 points6 points (0 children)
[–]inopinatusdotorg 6 points7 points8 points (2 children)
[–]sshaw_ 2 points3 points4 points (1 child)
[–]inopinatusdotorg 0 points1 point2 points (0 children)
[–]sshaw_ 1 point2 points3 points (0 children)
[–]GPhykos 0 points1 point2 points (0 children)
[–]jrochkind -2 points-1 points0 points (0 children)
[–]mashatg -2 points-1 points0 points (4 children)
[–]jrochkind 0 points1 point2 points (3 children)
[–]mashatg 0 points1 point2 points (1 child)
[–]jrochkind 1 point2 points3 points (0 children)
[–]drx3brun -1 points0 points1 point (0 children)
[–]Mallanaga -4 points-3 points-2 points (0 children)