From the Blog
-
Ruby Benchmark
If you just want to see how fast a bit of code is you can use the Benchmark module which is part of the Ruby Standard Library. If you want to compare two or more bits of Ruby code that do the same thing and see how fast they are against each other then you…
-
Link_to and Link_to_unless
Building a navigation bar in Rails is pretty easy. You simply write up something like: And you get a set of urls for your link that look like this: However if you are on the “Docs” page already then you dont’t really need the “Docs” link to be a link. It could just be text.…
-
Using Service Objects to extract business logic.
The Rails defaults work really well. You start with really nice, clean models and controllers. You can view them all as one page of code and hold an idea of what they do in your head. Problem is that they keep getting bigger as you add features and eventually they balloon out of control. Giant…
-
Why do we bundle exec?
A common question I get is why do we need to prepend a command with bundle exec? Running the command by itself seems to work most of the time so what is difference? We know that rake db:migrate (for example) is the command we want to run. We know that bundle install is how you…
-
Ruby Case statements from if/else
Reading nested if statements making you sad? Case statements can be the answer. Refactoring your if statements can clear up complicated code and make spotting bugs much easier. Nested if statements often lead to complex and hard-to-read code. They can grow over time as new conditions are added, making it difficult to maintain and debug.…
-
Classes, Hashes, Structs and OpenStructs in Ruby
Intro If I am looking to maximize the performance of a Ruby app what should I be using? Hashes, Structs, OpenStruct, or Classes? New Ruby programmers love hashes. I love hashes. They are very flexible and tempting to add in everywhere. Even when refactoring a slow part of the system in Kafka microservices so that…
-
Pushing Rails validations down to the database?
Ever open up a Rails console to debug a problem and come away wondering how the data got so funky? Despite our best efforts, the database will accept plenty of garbage data if you let it. There are tons of methods to bypass the Rails callbacks and validations while still updating your database. If you…
-
Ruby Native Extensions
In Ruby, native extensions (also known as C extensions or native gems) allow you to write parts of your code in the C programming language, which can be linked and executed as part of a Ruby program. Native extensions are typically used for performance-critical tasks, interacting with low-level system libraries, or providing access to functionality…
-
Using Spaced Repetition to Learn Programming
Do you ever wish that you could memorize an entire programming language and all of the libraries and APIs that you use constantly? Want to become as fluent in the technical concepts and jargon as you are in your native language? Well, that is what spaced repetition is for. Spaced repetition will help you efficiently…
-
Organizing large Rails projects
Do you have a Rails app that has gotten so big it is getting hard to know what is going on? When you have a new Rails app it is easy to tell what the app does by looking at the files in the models’ folder, but as the app gets bigger you often lose…