Show newer
Holm :ruby: boosted

Me: How do I work with currency?

Ruby: Just use BigDecimal.

JS: Deal with floating point math edge cases on every operation you do, forever.

Holm :ruby: boosted

A Noble Circle is free for PI Day. Hope you enjoy it. It is best played with sound on, and with a loved one.

Holm :ruby: boosted

Hey all! So who’s going to RailsConf this year?

Holm :ruby: boosted

Hi all, my name is Rodrigo and I've been developing with Ruby for 4 years now.
Lately I've been using Hanami at work and in some personal projects, but I really want to get back to develop some stuff with Rails again.

Holm :ruby: boosted

A script to run tests changed since master, pretty handy when checking PRs:

test_runner = File.exists?("Gemfile") ? "bundle exec " : ""
test_runner += if File.exists?("config/application.rb")
"rails test"
"ruby -Itest"
changed_test_files = `git log --name-only --pretty=oneline --full-index master..HEAD` { |f| f =~ /\Atest|spec/ }
exec "#{test_runner} #{changed_test_files.join(' ')}"

Holm :ruby: boosted

does anyone know *why* Kernel module exist? why isn't the methods just defined directly on Object?

blast from the past:

in 2014 I wrote a Ruby REST API system which had:

- a router that was based on a graph-structure: e.g. you say that "/users/:id" returns a User resource, and then you define the other actions available on a User resource

- strict types on input/output of actions

- usage of a `state` variable that is passed around internally to communicate across resources

this is like 80% of the GraphQL ideas

Derivation representation using binary subtree sets (by Elizabeth Scott, Adrian Johnstone, L.Thomas van Binsbergen):

always interesting to see a new Scott/Johnstone paper! going to have to see if I can use some of these techniques in my own experiments. /cc @jamey

Holm :ruby: boosted

Starting to write up some blog posts on generally useful programming topics. Partially to try to solidify my own knowledge - it's tough to write about a subject you only have a fuzzy understanding of. Hopefully it will be useful to someone else down the line as well!

First one is a intro, feedback welcome:

@jamey I should probably write something proper about it. it might be hard to understand if you're not in my head

Show thread

@jamey it's neat how Seq/Alt/Rep/Eps are "dissolved" due to and the only thing that matters while matching are terminal matchers (Char) and rule calls/returns.

Show thread

@jamey here we go:

should be able to recognize CFG with left-recursion, hopefully in O(n^3) time. there's a benchmark there for the ambiguous "n+n+n+"-grammar, and that seems to fit best in O(n^2) actually

$ du -sh .

oh. this was a neat repo.

$ yarn
$ du -sh .


Holm :ruby: boosted

How ERB uses `Binding` objects:

class DiyErb
def initialize(template)
@template = template

def result(binding)
@template.gsub(/<%=(.+?)%>/) do

Holm :ruby: boosted

I’d love to see better examples of using `#tap`, but I’ve mostly seen it used to refactor this:

metadata = {}
metadata[:id] = if user

That’s explicit. It creates a hash, adds a value if a condition is true, then returns the hash.

With `#tap`, the code is more difficult to read, and requires the next person to know what `#tap` does (“yields x to the block, and then returns x.”). 🤷‍♀️

{}.tap do |metadata|
metadata[:id] = if user

Show thread
Holm :ruby: boosted

Ruby snippet to print a line of code and its result:

def debug(&block)
puts block.source.strip
result =
puts "# => #{result}"

debug { 1 + 2 }

Holm :ruby: boosted

RubyGems 3 released!

looks like Ruby 2.6 on Christmas is landing with RubyGems 3 and Bundler 2


Show older

A Mastodon instance for Rubyists & friends