Re:Embed Crystal code directly in Ruby
by nomilk on Thursday April 11, 2024 @11:31AM
(#40003289)
Ha. TIL you can do 1_000_000.times do ... (equivalent to 1000000.times do ...). That's really nice.
[ Parent
| on HN ]
A lot of languages have added support for this over the last few years. It's a nice little quality of life improvement. I use it very regularly now. I find it really handy for currency amounts in cents, so I can say `10_00` for ten dollars, in cents.
Re:Embed Crystal code directly in Ruby
by throwiforgtnlzy on Friday April 12, 2024 @12:21AM
(#40009349)
Sorry, it's a been feature in a number of languages for decades. Perl has it at least as early as 5.005 in 1998. So naturally, Ruby had it since at least before 1.6 / 2002. Java added it in 2011. It didn't work with Python 2.1 from 2001, but I found it was added relatively late in PEP 515 in 2016 with Python 3.6.
As a latecomer, C23 went with ' just like C++ did almost 10 years earlier with C++14.
Install the Rubocop extension in your editor and it'll bug you about it every time you have a big int (kind of annoying when you're doing one-off scripts and embed "magic numbers" like IDs from the database lol)