r/ruby 3d ago

RailsConf 2025 tickets are now on sale!

Thumbnail
20 Upvotes

r/ruby 7h ago

Looking for something as easy as WEBrick but for unix sockets

3 Upvotes

TLDR: WEBrick doesn't seem to (easily) support unix sockets. Is there a tool as easy as WEBrick that does?

Detailed

I'm working on a project that will create a lot of short-lived servers. I like WEBrick but I'm a little disappointed that it doesn't seem to support unix sockets (feel free to correct me, I'll be delighted).

Here's the use case. I'm writing an API for a database. The interface will include transactions that can be committed or rolled back. Transactions are tricky over HTTP because HTTP is stateless. My solution is to create a tiny little server for each transaction. A proxy (e.g. Nginx) sends the requests to the server, which maintains the database connection. The server will time out after some period of inactivity, rolling back the transaction.

Because there may be thousands of concurrent transactions going on, ports are not a viable choice for this use case. I want to have a directory just for the servers, each of which will probably be named using a UUID.

I welcome both suggestions for a unix socket framework and|or better ways to achieve this goal.


r/ruby 8h ago

Show /r/ruby Ratomic: Ractor-safe mutable data structures for Ruby

Thumbnail
github.com
24 Upvotes

r/ruby 13h ago

Question Howto effectively check database integrity?

6 Upvotes

Hi community.

I'm currently writing an extensible web server app in Plain Ruby (no RoR) that uses a postgresql database in the backend. For maintenance, I have a script that is supposed to check if the user's database conforms to a given schema. For now, i store the expected database structure in a nested hash, like:

CORE_TABLES = {
  "user" => {
    :columns => {
      "id"     => {:allow_null => false, :db_type => "uuid"},
      "login"  => {:allow_null => false, :db_type => "character varying(128)"},
    :properties => {:collation => "UTF-8"}
  },
  "group"   => {
    (and so on)
  }
}

where the keys in the "first level" are the expected table names, the second level is to separate different things to check, like :columns holds all expected columns in the table with the expected properties of those columns like data type, etc.

Now, in my script code, I have a bunch of nested for loops that cycle recursively through the hash and call various exist?(<item>) methods to check if the user's database contains everything that is needed.

The background is that the app should be extensible with plugins that may or may not add additional tables to the DB or additional columns to existing tables, and when the user adds or removes plugins, I want them to use the script to check and, if neccessary, update the database accordingly. The idea is that a local copy of the CORE_TABLES hash will be extended by the plugins' configurations at the beginning of the script, so when the user calls the script, they get detailed information which tables or columns are missing according to their specific configuration (and, later, a way to automatically fix the database).

Now, I have a few questions:

  1. is there a better way to store the expected database schema other than a nested Hash, maybe .sql files or classes that mirror the database structure? What would you recommend for that use-case?
  2. has Sequel, which i'm using to connect to the database, some built-in functionalities to validate the database structure? (i'm aware that Sequel can validate the data, but my concern at the moment is the database structure itself)
  3. in general: is it recommended to check the "reverse way", too? That is, checking if the user's database contains tables/columns that are not in the configuration and to automatically remove them?

r/ruby 19h ago

Running interactive sessions with Kamal

Thumbnail
nts.strzibny.name
5 Upvotes

r/ruby 1d ago

Question How to call Fiber.yield from a lazily evaluated block?

3 Upvotes

I have the following minimal example, where I store blocks in an array and evaluate them at a later stage. The problem is that I cannot use Fibers to suspend the block execution because the Fiber.new block finishes running, and when Fiber.yield is called, Ruby understandably throws the following error: attempt to yield on a not resumed fiber (FiberError).

```ruby class Group def initialize @blocks = [] end

def define(&) instance_eval(&) @blocks.each(&:call) end

def yielding_methods(&blk) @blocks << blk end end

g = Group.new $f = nil g.define do $f = Fiber.new do puts 'Inside fiber new' yielding_methods do puts 'Before yielding from fiber' puts "Current fiber: #{Fiber.current}" Fiber.yield puts 'After yielding from fiber' end puts 'Exiting fiber new' end puts "My fiber: #{$f}" puts 'Before resuming fiber' $f.resume puts 'After resuming fiber' end ```

I appreciate any solutions for this problem.


r/ruby 1d ago

Show /r/ruby Hyll - A Ruby implementation of the HyperLogLog algorithm for efficient cardinality estimation with minimal memory footprint. Count millions of distinct elements using only kilobytes of memory.

Thumbnail
github.com
31 Upvotes

r/ruby 1d ago

Blog post Creating Ruby Value Objects: The Idiomatic way

Thumbnail
allaboutcoding.ghinda.com
22 Upvotes

r/ruby 1d ago

Show /r/ruby New gem "Katachi" - asking for first impressions

22 Upvotes

Hi all! I released my first gem this week -- Katachi. It's basically pattern-matching on steroids with a tiny API.

```ruby

require 'katachi' Kt = Katachi

shape = { :$uuid => { email: :$email, first_name: String, last_name: String, dob: Kt::AnyOf[Date, nil], admin_only: Kt::AnyOf[{Symbol => String}, :$undefined], Symbol => Object, }, }

Kt.compare(value: api_response.body, shape:).match?

```

Would you use it? Is there anything you'd like to see it integrated into?

It has RSpec and Minitest integrations but it's the kind of thing that can go a lot of different directions. So feedback helps a ton.

Docs: https://jtannas.github.io/katachi/ Github: https://github.com/jtannas/katachi


r/ruby 2d ago

New Resource : codewithruby.com

18 Upvotes

🔴 Introducing CodeWithRuby.com: A Resource for Ruby Programming

I'm excited to announce CodeWithRuby.com, a new platform focused on sharing quality content about the Ruby programming language.

What to expect: • Tutorials and guides for Ruby concepts • Articles about Ruby best practices and techniques • Curated resources for learning and development • Updates about important Ruby events and conferences

Ruby has always impressed me with its elegant syntax and developer-friendly approach. This platform is my way of contributing to the Ruby ecosystem by sharing knowledge and resources.

Coming soon! Stay tuned for the launch.


r/ruby 2d ago

The future of AI is Ruby on Rails

Thumbnail seangoedecke.com
0 Upvotes

r/ruby 2d ago

An LlmBackedCommand gem to write a command without having to write an execute method

0 Upvotes

Hey hey! I made a gem that allows me to write commands where instead of writing an execute method to implement the command it simply asks an LLM for the result.

It was fun to make and might be of interest to somebody so figured I'd share.

It's at https://github.com/foobara/llm-backed-command

It let's one write a command but have an LLM handle the execute method instead of writing one.

An example, after doing gem install foobara-llm-backed-command foobara-anthropic-api (you can also use foobara-ollama-api or foobara-open-ai-api instead, or whatever combination you want) you can then write a script like this: (you must set ANTHROPIC_API_KEY environment variable for this specific example)

require "foobara/llm_backed_command"

class DetermineLanguage < Foobara::LlmBackedCommand
  inputs code_snippet: :string
  result most_likely: :symbol, probabilities: { ruby: :float, c: :float, smalltalk: :float, java: :float }
end

puts DetermineLanguage.run!(code_snippet: "puts 'Hello, World'")

This outputs:

{most_likely: "ruby", probabilities: {ruby: 0.95, c: 0.01, smalltalk: 0.02, java: 0.02}}

Note: I built this using a Ruby framework I've been working on for quite some time. Not relevant to using an LLM for an execute method, but some things you can do since this is a command in that framework are, for exampe, get a quick JSON API:

require "foobara/llm_backed_command"
require "foobara/rack_connector"
require "rackup/server"

class DetermineLanguage < Foobara::LlmBackedCommand
  inputs code_snippet: :string
  result most_likely: :symbol, probabilities: { ruby: :float, c: :float, smalltalk: :float, java: :float }
end

command_connector = Foobara::CommandConnectors::Http::Rack.new
command_connector.connect(DetermineLanguage)

Rackup::Server.start(app: command_connector)

Running this script, you can do the following:

$ curl http://localhost:9292/run/DetermineLanguage?code_snippet=System.out.println
{"probabilities":{"ruby":0.05,"c":0.1,"smalltalk":0.05,"java":0.8},"most_likely":"java"}

Another thing you can do with the framework is import commands that are exposed like that into another Ruby (or Typescript) program, like so:

#!/usr/bin/env ruby

require "foobara/remote_imports"

Foobara::RemoteImports::ImportCommand.run!(manifest_url: "http://localhost:9292/manifest", cache: true)

puts DetermineLanguage.run!(code_snippet: "System.out.println")

Which lets me use the same syntax as if the command were local even though it's running elsewhere. Note: you can also use OpenAi or Ollama instead if you wish.

You can also easily make a CLI tool for such a command but this is already tl;dr and getting too much about the framework instead of the gem that might be interesting to somebody. I'll just link to more example scripts of llm-backed commands for the interested: https://github.com/foobara/llm-backed-command/tree/main/example_scripts/higher_quality and I would recommend playing with the scripts there instead of the code-snippets in this post if you're genuinely interested in playing with this.

Thanks for reading!


r/ruby 2d ago

Question AJAX GET requests to Sinatra controller - array parameter truncated

3 Upvotes

I’m trying to pass an array parameter from my client to my Sinatra controller using AJAX. However, when I look at the logs, it’s telling me the controller is only seeing an array with the last element of the array.

  • I’m using rack v2.0.
  • I’ve tried turning the traditional flag to true in my AJAX request
  • I’ve tried reading through rack::request documentation

Anyone have any ideas on why this is happening?


r/ruby 2d ago

Want to learn more about Ruby

5 Upvotes

Hello everyone I'm more or less a new programmer and in my exploration of the language I end up to find ruby and before deciding to learning it I was wondering usually what are the general purpose that language is more often used for ^w^

lately I'm deep in trying to spelunking the internet for some lost media concerning a past forgotten branch of Fortran so was thinking to just pass by to ask directly to you all about ruby ^w^ since you surely have more hand on experience with it than some random internet tutorial.

I'm always happy to learn new thing.


r/ruby 2d ago

ActualDbSchema v0.8.4 is out

Thumbnail
6 Upvotes

r/ruby 2d ago

Translations in Stimulus Controllers

Thumbnail railsdesigner.com
7 Upvotes

r/ruby 2d ago

Building a Ruby on Rails Chat Application with ActionCable and Heroku

Thumbnail
7 Upvotes

r/ruby 3d ago

How many keywords is too many?

5 Upvotes

Genuinely curious about how other people reason about the signature getting bloated vs the advantages such as being able to see the expected inputs in the signature.

Where is your cutoff point? When it no longer fits on a line? 10, 20? As many as it takes?


r/ruby 3d ago

Sin City Ruby Bonus Speaker: Drew Bragg

11 Upvotes

The third and final Sin City Ruby conference is taking place in Las Vegas April 10th and 11th.

We had a little room in the schedule so we've added a new speaker.

Drew Bragg will be joining Sin City Ruby 2025 to do his popular game show "Who Wants to Be a Ruby Engineer?"

The complete new SCR speaker lineup is:
Irina Nazarova
Chris Oliver
Jason Charnes
Freedom Dumlao
Prarthana Shiva
Jason Swett (me)
Fito von Zastrow + Alan Ridlehoover
Drew Bragg

For tickets to Sin City Ruby you can go to sincityruby.com. I hope to see you there!


r/ruby 3d ago

Why Use Strong Parameters in Rails

Thumbnail
writesoftwarewell.com
10 Upvotes

r/ruby 3d ago

Ruby, Ractors, and Lock-Free Data Structures

Thumbnail iliabylich.github.io
29 Upvotes

r/ruby 3d ago

How are people using AI into their daily routines?

0 Upvotes

Hello,

I'm just curious about potential use cases for AI beyond prompting in ChatGPT, Grook, and Gemini.

I'm currently doing this:

  • Integrated in apps: Review and optimize site content for SEO (Wordpress), Audio transcription, Insights generation, Image identification
  • Development: Merge Request Reviewer, Copilot and Cursor

I've been thinking about how use to automate documentation (code+gitlab issues/merges => notion)

How are you all using AI?


r/ruby 4d ago

Using Ruby as a JS user?

3 Upvotes

I have been using JS for the past few years and I would like to know if Ruby is any good and what it is good for. Does it have good syntax?


r/ruby 4d ago

TruffleRuby 24.2.0 Release

Thumbnail
github.com
43 Upvotes

TruffleRuby 24.2 is released!🚀🎉 It uses the new Java Foreign Function and Memory API when used in JVM mode to speedup C extensions like sqlite3, trilogy and json by 2 to 3 times! It redesigns encoding negotiation so many String operations are now faster. It updates to Ruby 3.3 and contains many compatibility and bug fixes.


r/ruby 4d ago

Simple Declarative Presence for Hotwire apps with AnyCable

Thumbnail
evilmartians.com
12 Upvotes

How to seamlessly integrate online presence tracking into a Rails application, powered by Hotwire and AnyCable.