- It is not obvious what data you have access to. Your code appears to have access to the user object, but most of the data is missing.
- Similar to #1, other helpers/decorators/etc. that you have in your codebase may have model requirements that are not obvious as well. You pass along this partial object, and you may have some unintended consequences.
- If you use any kind of caching, you may accidentally expose this partial object to completely unaware parts of your app
pluck
- As suggested in the article, you may be giving up some of your model niceties. Still, it is usually a worthwhile trade-off if the amount of data returned warrants optimization. It can also help expose some code that should not live directly within your model.pluck
andStruct
- when using pluck gets too messy, you can always take the data returned and load it into a struct (or a PORO).
You can put this in the “the more you know” category.
Phlex is a framework for building fast, reusable, testable views in pure Ruby.
I look forward to trying Phlex for a small project in the next couple of weeks.
I am still a fan of ViewComponent as well, but the markdown support for Phlex might be a game changer for me.
ShortRuby - The best part about checking email on Monday morning is finding a new ShortRuby newsletter.
This is a weekly newsletter about what happens in Ruby’s world (mainly on Twitter) curated by @lucianghinda
The CodingFont game is excellent, but what if you want to do a quick test drive?
Well, here you go Programming Fonts.

CodingFont is a fun bracket game that helps you pick a coding font.
I recommend checking the Hide Font Names
option.
My winner was Azeret Mono. A younger me would have picked a smaller font, but I will give this one a shot for a couple weeks.

Optimizing ActiveRecord SQL Memory Usage in Rails
A decent suggestion by Patel Urbanek - Easy to Miss Way to Optimize ActiveRecord SQL Memory Usage in Rails.
Urbanek recommends using select
in your ActiveRecord queries to limit the fields returned and thus save memory. While this certainly will work, I find it messy long term.
I typically use two approaches:
I have not spent any time with Hanami, but I am hoping to change that.
I like Sinatra when your goal is to respond to requests and do not need the full Rails functionality and ecosystem.
Hanami looks like it fits somewhere between the two.
Finding Duplicate Charactes in Multiple Arrays with Ruby
We needed to find duplicate characters in multiple arrays for Saturday’s Advent of Code.
In the first part of the problem, it was among two arrays, so I did something quick like this:
|
|
This worked as expected, but in part 2, you needed to perform a similar search across three arrays.
I could have chained a second select
or duplicated the line entirely, but I figured there was a more straightforward way…and of course, in Ruby, there is almost always a more straightforward way.
I do not have a traditional comp sci background, so my mind rarely jumps to Bitwise operators, but in this case, this is the Bitwise &
operator is exactly what we needed.
@scott pointed this is not Bitwise when dealing with strings:
It is the unary and operator. On arrays, #& is a method that returns the set union of two arrays. On integers, it is indeed implemented as a bitwise and.
|
|
Even better, this easily scales across N arrays.
I have not had much use for Sizzy in while, but fired it up today and was instantly re-impressed. One of the more indispensable tools for frontend web development.
Bare Metal FizzBuzz
If I were deploying this somewhere, I would lean towards something that looks more like the readable_solution
below.
But for the sake of the challenge:
|
|
If this were a one-liner competition, I would like my chances. 😄
|
|