
5 days per week, a ruby 💡tip - By @blaked_84
🇫🇷
Joined July 2018
- Tweets81
- Following1
- Followers459
- Likes16
Splat operator and array
💻 Copyable example at: beckr.fr/daily_ruby_tips
Writing large Integers
💻 Copyable example at: beckr.fr/daily_ruby_tips
Here documents
📖 Doc: ruby-doc.org/core-2.5.0/doc/…
💻 Copyable example at: beckr.fr/daily_ruby_tips
4
Enumerable#find
Do you know you can pass a proc to `find` to return a default value if no object matches?
📖 Doc: ruby-doc.org/core-2.5.1/Enum…
💻 Copyable example at: beckr.fr/daily_ruby_tips
Enumerable#partition
📖 Example from ruby-doc: ruby-doc.org/core-2.5.1/Enum…
💻 Copyable example at: beckr.fr/daily_ruby_tips
Unescaping text.
Sometime I have to handle escaped text and... no regex tip here. Since ruby 2.5 I use `undump` 😀
📖 Doc: ruby-doc.org/core-2.5.0/Stri…
💻 Copyable example at: beckr.fr/daily_ruby_tips
`split` is not the only solution to split strings.
📖 Doc: ruby-doc.org/core-2.5.0/Stri… & ruby-doc.org/core-2.5.0/Stri…
💻 Copyable example at: beckr.fr/daily_ruby_tips
String#strip
I'm sure you know "strip". What about "strip!", "lstrip" and "rstrip"?
📖 Doc: ruby-doc.org/core-2.5.0/Stri…
💻 Copyable example at: beckr.fr/daily_ruby_tips
4
String#center
Before, I used `puts "###### Title ######"` to print title in stdout. But I hated to center a text manually. Now I use 👇
📖 Doc: ruby-doc.org/core-2.5.0/Stri…
💻 Copyable example at: beckr.fr/daily_ruby_tips
String#casecmp?
If as me, you currenlty use `"aBcDeF".downcase == "abcdeF".downcase` look at this 👇
📖 Example from the ruby doc: ruby-doc.org/core-2.5.0/Stri…
💻 Copyable example at: beckr.fr/daily_ruby_tips
Reduce
📖 Example from ruby doc: ruby-doc.org/core-2.5.1/Enum…
💻 Copyable example at: beckr.fr/daily_ruby_tips
Struct VS OpenStruct
💻 Copyable example at: beckr.fr/daily_ruby_tips
8
I ❤️Struct!
Struct provides a nice way to organise data inside a class.
Exemple inspired by this article by @leighchalliday leighhalliday.com/ruby-struc…
📖 Doc: ruby-doc.org/core-2.5.0/Stru…
💻 Copyable example at: beckr.fr/daily_ruby_tips
We continue with other Time tips.
And if like me, you never remember the strftime syntax – from ISO 8601, yes it is standard – you can use foragoodstrftime.com by @mbuckbee.
💻 Copyable example at: beckr.fr/daily_ruby_tips
monday?
💻 Copyable example at: beckr.fr/daily_ruby_tips
respond_to?
📖 Doc: ruby-doc.org/core-2.5.0/Obje…
💻 Copyable example at: beckr.fr/daily_ruby_tips
7
Today I discovered the `itself` method. It's a kind of public `self`.
And I wondered if there is real world usage of this method. 👇
👉Example from karolgalanciak.com/blog/2017… by @Azdaroth
💻 Copyable example at: beckr.fr/daily_ruby_tips

















