All posts tagged with 'ruby'
How the Ruby Interpreter Creates Methods on the Fly
(And why it matters!) I was lucky enough to attend last year's EuRuKo, the travelling European Ruby conference. A theme of the conference (for me) was Ruby's infamous embrace of metaprogramming, which I've had little exposure to in my day-to-day as a Rails dev. The approach to this discussion was inspired by this great talk by Masafumi Okura on Code Reading, and much of the detail comes from the book… Continue reading
Ease into Ruby with a Python background
Starting your first role as a software engineer and having no knowledge of the programming language used in your organisation sounds like a nightmare at first, as thoughts of the imposter syndrome that many of us seem to suffer from these days start to take over. But worry not. At FreeAgent the environment is very friendly and relaxed, allowing you as a new joiner to focus on learning and integrating… Continue reading
Readable Dates in Rails
I was playing around in Swift recently, and wanted a reference to 'one day ago'. This is simple enough in human terms: if it's 9:30 on the 18th of September, 'one day ago' means 9:30 on the 17th of September. The Swift code to do this looks like this: Calendar.current.date( byAdding: .day, value: -1, to: Date.now ) ...and that's just a bit much, isn't it? First we need to access Calendar.current, a singleton… Continue reading
Type checking in Ruby – Part 1
Over the course of a career in software engineering, we learn to love elements of our tooling and dislike others - that’s perfectly natural. As requirements change, including our own need to improve as engineers, so does what appeals to us when reaching for a new framework, language or library. A common path for lots of engineers will have been to learn something like C or C++, both strongly typed… Continue reading
An introduction to object-oriented programming
Object-oriented programming, or OOP, is a programming paradigm centred around the concept of objects. This article will aim to provide a basic understanding of objects, classes, OOP principles and various other concepts within the paradigm. Code examples will be mediated in the Ruby programming language, which is an example of an object-oriented language. In Ruby, any value is an object, even data types like String and Integer, which are often… Continue reading
Titlecase, underscore and laser guns
Not so long ago, I had an opportunity to peek under the hood of titlecase and underscore methods, the tiny cogs of the “Rails magic” machine. The latter turned out to be a very interesting function—a lot of hard-to-follow transformations, secret injections and the like. All of these bits significantly contributed to an odd-looking bug I’ve been working on. Today, we’ll unravel the implementation of both methods and look in… Continue reading
Timecop vs Rails TimeHelpers
TL;DR - You probably can’t replace Timecop with Rails' built in TimeHelpers, as TimeHelpers only recreates Timecop’s freeze method, and can’t handle nested travelling. Timecop is the go-to gem for testing time-dependent code, as it allows you to manipulate the current time during test runs. This is important because without control over the time, flakey tests can emerge in your codebase. A very simple example is testing the created_at attribute… Continue reading
Testing Child Processes in Ruby
I was recently writing a piece of code that we wanted to act as a supervisor of child processes. We wanted to ask this supervisor the following “Hello there, would you mind running this task in a child process? Thanks!”. From here the supervisor would create a process, keep track of it so we can stop it if necessary, and run the given piece of code in it. This supervisor… Continue reading
Breathing New Life into Dormant Code
In the Tax Engineering team at FreeAgent we’re currently working on adding Corporation Tax and Final Accounts filing to our application as we continue our mission to help our customers relax about tax. We’ve been working on these features since June and recently released the Final Accounts report and the CT600 form, but what you might not know is that work on this project originally began back in 2017. So… Continue reading
Down the Ruby Mine, Part III: Splat and splat again
Hello and welcome to another Down the Ruby Mine. I’m Sam, one of the Engineering Interns working at FreeAgent over the Summer and I am here to shed some light on a Ruby language feature. If you’re out of the loop, you may have missed my previous posts which can be found here and here. Today we’ll be diving into the most questionably named Ruby feature out there: splat. Functions… Continue reading