Weekly Brain Dump #4
At a Glance
- Ruby Squasher: Redesigning Taylor’s
squashcommand - Interesting Links: Cool things I found this week
Ruby Squasher
I got the itch to redesign the squash command in Taylor
Engine because the current implementation leaves a lot to be desired.
The Way It Works Now
Given these three files.
# game.rb
require "lib/game"
Game.call()
# lib/game.rb
require "lib/player"
class Game
def self.call
puts "Run the game!"
end
end
# lib/player.rb
class Player
def self.call
puts "Does player things"
end
end
If we called taylor squash --stdout we would see the following code printed to
standard output.
# Start game.rb
# Start ./lib/game.rb
# Start ./lib/player.rb
class Player
def self.call
puts "Does player things"
end
end
# End ./lib/player.rb
class Game
def self.call
puts "Run the game!"
end
end
# End ./lib/game.rb
Game.call()
# End game.rb
You can see that I’ve just replaced the require lines with the content from
the files. This is actually very different to how require works under the hood
and can lead to discrepancies between running in development and release builds.
This is the big motivator behind redesigning taylor squash.
The Redesign
My plan is to distribute this as both a regular Ruby gem and an mruby mgem if I can get it to a point I’m happy with it.
The design I’m currently experimenting with is a bit more complicated but should
lead to a more consistent operation between development and release. I would use
lambdas to keep the namespaces clean and an overridden require
method. I’ve put a functional example below to illustrate what the output could
look like.
You can see this working in your browser.
#!/usr/bin/env ruby
SQUASHER_FILES = {
"first_require" => -> {
class First
def self.call
puts "First"
end
end
},
"second_require" => -> {
class Second
def self.call
puts "Second"
end
end
},
}
class Squasher
def self.inject
original_require = Kernel.method(:require)
Kernel.define_method(:require) do |file|
if Squasher.files.has_key?(file)
Kernel.module_exec {
Squasher.files[file].call
}
else
original_require.call(file)
end
end
end
def self.files
SQUASHER_FILES || {}
end
end
Squasher.inject
require "first_require"
First.call
require "second_require"
Second.call
Running that will give you the following output.
First
Second
There’s definitely flaws with this but I think it’s a pretty promising start. I do also plan to squash files from gems into the output but would need to do something special for native gems.
Interesting Links
Create Your Own Programming Language with Rust Book: This book has been in development for 6 years and just released this week. I’ve had a strong desire to make my own language recently and this has only added fuel to that fire!
Writing Windows 95 software in 2025: A fun guide on setting up a development environment for Windows 95 on MacOS.
The Case for Blogging in the Ruins: Why blogs are still relevant and what needs they fill versus social media.
Pico-View 2025: Reflecting on everything that happened with PICO-8 during 2025. This is a magazine made by teachers and is always amazing, I absolutely recommend following them.
Portable mruby binaries with Cosmopolitan: I love seeing people doing interesting things with mruby and I had never heard of Cosmopolitan before.
How I beat Factorio on 1,000 Floppy disks: A YouTube video showing DocJade building a filesystem on top of 1,000 3.5” floppy disks and running Factorio from it.
How Github monopoly is destroying the open source ecosystem: A stark reminder that GitHub is a single point of failure and has warped people’s perspectives of open source software.