langage-ruby.hashnode.devElixir-like pipes in RubyIf you use Elixir (and the Phoenix framework), you’ve probably admired the beauty and power of the |> pipelines. For example: "String" |> add(" is a common type") |> IO.puts # => "String is a common type" In Ruby, the same mechanism can be achieved ...Dec 5, 2025·2 min read
langage-ruby.hashnode.devMembership in a list (Set)Using Set is probably the most convenient way to check for membership in a list since values are stored like in a Hash. Set uses the === method to check membership, which allows: case 'apple' when Set['bean', 'cauliflower', 'carrot'] "vegetable" wh...Dec 4, 2025·1 min read
langage-ruby.hashnode.devChecking for the existence of a Hash keyYou can test whether a key is present in a hash and return a precise message when it fails thanks to the KeyError exception raised by #fetch: begin {one: "1", two: "2"}.fetch(:three) rescue => e p "The key #{e.key.inspect} cannot be found in #{e....Dec 3, 2025·1 min read
langage-ruby.hashnode.devSemi-predicate methodsIn many languages, “predicates” are methods that return either true or false. In Ruby, they’re traditionally marked with a trailing question mark. def are_you_ok? if yes true else false end end This question mark is only a convention. ...Dec 2, 2025·1 min read
langage-ruby.hashnode.devLes méthodes semi-prédicativesOn appelle dans les différents langages « prédicats » les méthodes qui retournent soit true soit false. dans la beau du langage Ruby, elles sont reconnaissables au fait de porter un point d’interrogation à la fin de leur nom. def est_que_tu_vas_bien?...Dec 2, 2025·2 min read