TiL: Double Splat Nil in Ruby

How Ruby can do what you don’t expect Ruby is a very clever language. It will take the code you’ve written and do it’s best to make sure it runs. Take for example the following method call: method_one('Hello', param_two: ' world') That looks simple enough as it takes two arguments, one positional and one keyword. Now, lets take a look at what the method is actually doing: def method_one(param_one, param_two) p param_one, param_two end Interesting. At first glance it might appear that this method would print Hello world, but there is a subtle difference between how the method has been defined and how it is called. Let’s see what it actually outputs: ...

June 9, 2025 · 2 min · 384 words · George Bell

Checking for existing user in Atlas

Ever had to create users in MongoDb Atlas in AWS for use when making database enquiries in a functional test written in Ruby? Ever wished you could leave it to the test pack to check if one already exists and create one when required, instead of hand cranking a new one every single day of your life? Well now you can!!! But, first things first What is MongoDB Atlas and what do its users do? ...

May 29, 2025 · 2 min · 349 words · Peter Squire

TiL: Using the max_by method in Ruby

When trying to get an upper or lower value for a certain field in an object can be cumbersome. But when using the max_by method, this can actually be done quite elegantly. For example: persons = [ { "name" => "John McJohnson","age" => 34, "topScoreAtBowling" => 205}, { "name" => "Davey Jones","age" => 304, "topScoreAtBowling" => 300}, { "name" => "Willy Wonka","age" => 50, "topScoreAtBowling" => 200} ] If we had a bowling competition and wanted to see who had the topScoreAtBowling field, rather than looping through the array and looking at each object, we can simply use the max_by command as follows: ...

February 20, 2025 · 1 min · 170 words · Tomos Griffiths

Toggling Ruby scenarios in Drone using secrets

TiL how to toggle Ruby scenarios to be run using CI pipeline secrets Scenario In a relatively niche scenario, we have functionality that is being temporarily removed while new code is being developed. While we still want to keep our current scenarios for function X to use them again when it’s reintroduced, if they are left to run in our pipeline, every build will fail until it is reintroduced again. ...

November 7, 2024 · 4 min · 707 words · Leighton Taylor

TiL: The difference between exec and system in Ruby

Ruby provides a few different ways to execute commands against the underlying kernel programmatically, but they all work slightly differently. The simplest way to execute a command againts the shell is to surround it in backticks. For example, the following will run the command date and return whatever was output to $stdout. current_date = `date` However, there are also more explict methods you can call. In particular, there is exec and system which look like they do the same thing at a quick glance. However, they actually work very differently once you get down into what they are doing. ...

September 23, 2024 · 2 min · 425 words · George Bell