Ruby is a community, too
Behind Ruby there are people – and they meet. The biggest Ruby conference is RubyKaigi in Japan ("kaigi" means conference): running since 2006, nowadays in a different city every year, three days of talks in Japanese and English, with Matz and the people who develop Ruby itself right in the middle. There is also RubyConf in the USA, EuRuKo in Europe, Rails World and meetups in many cities.
Weren't there? RubyEvents.org collects the videos of thousands of Ruby talks, free and searchable, and shows which conferences and meetups are coming up. In this lesson we follow one Rubyist through three talks: Tomoya Ishida (@tompng). He is a Ruby committer and maintains IRB, the tool from lesson 47.
At RubyKaigi 2024 in Okinawa, tompng gave the keynote "Writing Weird Code" – spoken in Japanese, with English slides. His point: Ruby can be wonderfully readable – and gloriously weird. A few ideas from the talk, in our own examples. First, notations you half know already:
p %(bacon) # like "bacon"
p %w[Kaz Isi Chunky] # an array of words
p "RubyKaigi %d" % 2024 # String#% fills in %d
p ?a # a single character
p %%% # %…% with % as the bracket: empty
p %%%%%%% # empty % empty%(…) and %w[…] write strings and arrays of words, ?a a single character, and String#% fills in placeholders. The bracket after % can be almost any character – even % itself: %%% is an empty string, and seven percent signs are "empty % empty". tompng showed that every run of 4n + 3 percent signs is valid Ruby. Names can be weird, too:
🦊 = "Chunky"
🥓 = "bacon"
puts "#{🦊} loves #{🥓}"
both = <<~ONE + <<~TWO
First line
ONE
Second line
TWO
bothVariable names may be Unicode, emoji included (which doesn't necessarily make them more readable). And two heredocs on one line: Ruby reads the line to its end first, then picks up the texts one after the other. Cases like this used to confuse IRB's indentation; since IRB 1.7.1 it gets them right.
Regular expressions can do more than you would think – this one spots prime numbers without a single division in the code:
def prime?(number)
number > 1 && ("x" * number) !~ /\A(xx+)\1+\z/
end
(1..30).select { |number| prime?(number) }9 becomes "xxxxxxxxx". (xx+) captures a group of at least two x, and \1+ demands that exactly this group repeats to the end. That only works if the x split into groups of equal size – that is, if the number is composite. The regex engine tries every group size to find out: slow, but beautiful. An old trick from the Perl world that tompng showed in his talk. And a puzzle to finish: what comes out here?
FOX = "Chunky"
module Forest
FOX += " Bacon"
end
[FOX, Forest::FOX]FOX += " Bacon" means FOX = FOX + " Bacon". Reading finds the outer FOX, assigning creates a new Forest::FOX – two constants. A tool that understands Ruby code has to know such cases: the tests of tompng's type completion for IRB check exactly this one.
Why all this? In the talk, tompng gives three reasons: weird code is a puzzle that's fun. Cracking it, you understand Ruby more deeply. And weird code finds bugs – in IRB, in the parser – that well-behaved programs never run into. For him, a contest for weird code is what got him contributing to IRB and Reline. In the second part of the keynote he showed six programs on the theme of Okinawa, such as a file that is a picture of an Easter lily (a BMP) and a Ruby program at the same time, and one that endlessly weaves patterns of Okinawan Minsa weaving in the terminal – they are on GitHub.
That contest is called TRICK (Transcendental Ruby Imbroglio Contest for rubyKaigi). Since 2013, Rubyists have been sending in programs meant to surprise, excite or amuse the judges, Matz among them. tompng won gold in 2022. At TRICK 2025 he was a judge himself – and still took 3rd, 4th and 5th place, because this time the judges sent in programs too. All the winners are on GitHub with explanations, under the MIT licence.
A year later, at RubyKaigi 2025 in Matsuyama, tompng explained in "Analyzing Ruby Code in IRB" how IRB reads your code while you type: to colour it, to tell whether your input is finished or still lacks an end, to indent and to complete. For that, IRB looks at code in two ways – as a sequence of tokens, the "words" of the code, and as a syntax tree – and weird code is the acid test. Helping it is Prism, the parser that Ruby itself has used to read your code since version 3.4. Try it:
require "prism"
Prism.lex("puts 6 * 7").value.map { |token, _state| token.type }Prism.lex splits the code into tokens: a name, a number, a star, a number, the end. That is how IRB knows, for example, what to colour how. Prism.parse builds the whole syntax tree – and success? tells whether the code is complete and valid:
puts Prism.parse("def fox").errors.last.message
["def fox", "def fox\nend", "[1, 2,", "\"bacon"].map do |code|
[code, Prism.parse(code).success?]
enddef fox lacks its end, [1, 2, its bracket, "bacon its quote: here IRB waits for the next line. Real IRB also tells code that is merely unfinished from code that is already wrong – that was part of the talk, too. This page uses the same idea: ⚡ Live only starts your code once it parses.
On RubyEvents.org you'll find talks on almost every topic of this course – try searching for "IRB", "Prism" or "TRICK". Many RubyKaigi talks are in Japanese, but their slides are mostly in English; the talk's page on rubykaigi.org links them. RubyEvents also shows which conferences and meetups are coming up and which are looking for talks. Ruby conferences are glad to see new faces – in the audience and on stage.
inputs(lines) gets the lines someone types one after the other and returns the finished inputs, the way IRB would run them – the lines of one input joined with "\n". inputs(["x = 1", "def double(n)", " n * 2", "end"]) gives ["x = 1", "def double(n)\n n * 2\nend"].require "prism"
def inputs(lines)
# collect lines until Prism.parse(code).success?
end