Ruby is a beautiful programming language.
According to Ruby’s official web page, Ruby is a:
“dynamic, open source programming language with a fo...
For further actions, you may consider blocking this person and/or reporting abuse
Fabulous post. I’m not sure I’ve read a post that expresses the wonder of Ruby so coherently.
Nice.
A common problem that I have been enjoying the use of
tap
on is populating an array with optional elements.Instead of:
... (which creates two Array objects) I have switched to ...
... or ...
As is often the case, simple examples don't really do this justice. When you have a lot of complexity about what is going to be added and when, it comes into its own.
Semantically, what I particularly like is the way that
tap
lets you use a block to say:Lots of hot tips in here!
I like to use the rubocop gem to watch my back when I'm writing ruby. It will point out a lot of non-idiomatic bits of your code and suggest ways to improve them in line with this great article.
Awesome! I love programming with Ruby too.
Recently discovered that the .any method can be used as an iterator too.
results.any? do |result|
end
Look forward to more.
This is an awesome list of a bunch of great tips you've put together! Thank you for it!
Ruby was (and retrospectively, I'm thankful for it) the first programming language I learned. I've since picked up PHP, JavaScript and am working on Elixir, but I consider myself a proud Ruby programmer.
With the progress being made on the Ruby 3X3 goal, as well as the fact that nothing I have tried comes close to the productivity i get from working with Rails, I don't see that changing anytime soon.
I'm a Rubyist, and your list is a perfect example of why.
Correct me if I'm wrong, but
[1, 2, 3, 4, 5].select(&:even?)
should actually be slower than explicitly writing a block, as it creates a Proc object implicitly by callingto_proc
on the Symbol. There might of course be some optimization going on in the background that I don't know about. (EDIT: I totally agree that it looks neater though, and I use it a lot myself)Nice article! It's worth pointing out that safe navigation is not a replacement for try, though. I've made this mistake a few times and had it bite me :D
Thanks a lot for writing this! I've been looking for ways to use the same filter that ES6 offers but couldn't figure out the syntax in ruby. This post is now bookmarked for reference!
Thanks for the post! In the following example under Select...
...I noticed that after the first line, even_numbers is:
[nil, 2, nil, 4]
`Why does
element if element.even?
return nil when
element.even?
is false?
~s
Thank you very much for this tutorial. There are so many tips here ...
Thanks! Glad you liked it!
you can as example a programatic lambda
Tap is my favorite!
Great intro :)
Awesome post!
This really captures why I love Ruby so much: it's really expressive and natural when done right.
totally love this--i came back to programming after something like a 15-year hiatus, and ruby was just what i needed to fall back in love with coding (and see it for the linguistic art it truly is!)
The Idiomatic Ruby cheat sheet
This Post Is Fantastic... Very clear, well explained.
Thank You!!