My favorite parts of Ruby
Disclaimer 1 first of all I’d like to say that I really like Ruby. I write a ton of Ruby code every single day and I prefer it over other languages. Please, do not take it seriously, Ruby is nice, and this post is mostly a joke.
Disclaimer 2 I’m not going to cover popular things like flip-flops (thanks God they are deprecated in 2.6.0).
I was thinking for a while which item should go first, but finally I had to give up. I think all items are funny.
Regexp ‘o’ flag
I don’t even know if there’s anyone in the world using it. o
flag is a very, very magical thing that “freezes” a regexp after parsing:
pry> 1.upto(5) { |i| puts /{i}/o.source }
1
1
1
1
1
pry> 3.times.map { |i| /{i}/o.object_id }
=> [70135960411140, 70135960411140, 70135960411140]
That’s a hacky way to define an inline regexp as a constant. It is a constant because its value is constant (object_id
returns the same value)...