Heredocs in Ruby are quite common, quite flexible, and… somewhat weird. Still, this doesn’t stop people from suggesting more features for them, like this (rejected) proposal for an anonymous heredocs syntax: # regular Ruby code Markdown.render <<~MARKDOWN # Hello there This is a Markdown file. See? 1. This is a list 2. With items 3. And more items MARKDOWN # proposed syntax Markdown.render <<~ # Hello there This is a Markdown file. See? 1. This is a list 2. With items 3. And more items ~>...| Meta Redux
Ruby is famous (infamous?) for giving us many ways to do the same thing. One aspect of this is that quite a few methods in core classes have aliases, especially in the Enumerable module. E.g.: collect -> map inject -> reduce detect -> find select -> find_all Most Rubyists are probably aware that the “original” method names (collect, inject, etc) were inspired by Smalltalk and later the aliases where added to reflect the naming trends in the functional programming community. Enumerable#sel...| Meta Redux
I guess most Rubyists know that you can use the methods Integer#succ1 and its alias Integer#next to increment a number. E.g.: 1.succ # => 2 The method is rarely used directly, but it’s used internally by ranges to compute the elements within the range boundaries: (1..10).to_a # => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] It’s not so widely known that strings also implement succ. The official docs describe String#succ like this: Returns the successor to str. The successor is calculated by increment...| Meta Redux
String#split is a pretty-well known and commonly used method. Still, its behaviour in some cases might surprise you: irb(main):001:0> 'foo.bar'.split('.') => ["foo", "bar"] irb(main):002:0> '...'.split('.') => [] irb(main):003:0> 'foo...'.split('.') => ["foo"] irb(main):004:0> 'foo'.split('.') => ["foo"] irb(main):005:0> ''.split('.') => [] No comment needed. Keep Ruby weird!| Meta Redux