RubyLLM: A delightful Ruby way to work with AI

(github.com)

377 points | by ksec 3 days ago

21 comments

  • Multiplayer 7 hours ago
    Saw this gem of a gem on reddit earlier today and there were some trollish comments about no one using ruby anymore blah blah blah which quietly bummed me out. Surprised and Delighted to see it as #1 here on HN tonight!
    • adamtaylor_13 6 hours ago
      There’s a lot of folks who get immense schadenfreude talking about things they know nothing about to strangers on the internet who also don’t know anything.

      Don’t let it bum you out.

    • jstummbillig 2 hours ago
      Ruby, specially with Rails, is particularly suited for AI coding, because of how mature it is and convention over configuration: Most of the important stuff is up to date in the model, and the entire thing comes with a fairy comprehensive set of ideas of how to to be used cohesively to built entire apps.
    • Lio 4 hours ago
      It's worth remembering that the trolls that complain about Ruby do so because they care about it.

      You'll often see the same names coming back on every post to angrily insist that no one is interested in Ruby

      ...apart from them obviously because if they didn't they would be busy trolling something else. :P

      • bmacho 3 hours ago
        > It's worth remembering that the trolls that complain about Ruby do so because they care about it.

        I don't think so. I mean there are complains about stuff you care about like people complaining about Healthcare. (edit: there are other forms of caring, see my grandchild comment)

        Dissing on Ruby is definitely not this, they are not Ruby users wanting Ruby to be better. They don't even know Ruby apart from dissing on it is socially accepted, and makes them feel good.

        • mosselman 2 hours ago
          Usually people get huffed up about stuff they care about. Caring doesn’t mean wanting it to be better, it could also mean get worked up about.

          Surely a one-off comment about nobody using Ruby doesn’t mean you “care”, but if it is true that it is the same people who keep commenting, they obviously care.

          Is it because they are jealous of the beauty of Ruby/Rails, as a Rubyist I’d think so, but who is to say really. Maybe they worked at a company where they replaced whatever their favourite stack is with Rails and they have hated Ruby ever since. It could be anything.

          You wouldn’t keep responding to stuff you don’t care about at some level.

          • bmacho 2 hours ago
            Equating caring and wanting it to be better was a mistake on my part. It made my comment not true, and it made you worked-up. Sorry for that.

            All in all, I don't think that other forms of caring apply either. I think that parroting "Ruby is dead" doesn't mean that they care about Ruby, it's just a thing people like to parrot, without the meaning realizing in their heads. A form of bonding, a form of distraction, a form of opening to a social interaction, a form of self-reassurance etc. It is lot of things, and caring about Ruby at all is usually not among those (IMO).

            • mosselman 1 hour ago
              Haha I am not worked up. I just care it seems.

              I agree. Parroting some meme isn’t caring per se. But I was working under the assumption that the statement that it was the same names who keep doing it. If you say “Ruby is dead” 5 times a year it isn’t necessarily “caring” if it becomes 100 times a year there is something else at play.

      • IshKebab 1 hour ago
        I'm not sure what your point is. I care about Ruby and want it to die because I have worked on the Gitlab codebase, which is written in Ruby. It's a bad language and it stopped me being able to understand behaviours and fix bugs.

        In contrast I have also worked on VSCode which is similarly huge but written in Typescript. Faaaar easier to work with, enough that I've been able to contribute a couple of medium sized features and several bug fixes.

        So when people say "yeay Ruby" I try to discourage them because I don't want more Ruby code in the world that I might have the misfortune of having to interact with in future.

        • steve_gh 12 minutes ago
          I think you are confusing the beauty and elegance of the language with the crap thatpeople write.

          My experience is that the sort of folks who misuse Ruby's powerful features are the sort of idiotes who dont realise that because a thing can be done, doesn't mean that it should be done. These are the sort of people who are capable of misusing most languages.

        • bob1029 41 minutes ago
          IIRC Github was originally written in Ruby as well.

          Now that they use something "far easier to work with", the UX gets to suffer accordingly.

          I've never been in a situation where making the customer happy was synonymous with applying best practices to the tech stack or otherwise making it so everyone and their dog can contribute.

    • someothherguyy 5 hours ago
      > some trollish comments about no one using ruby anymore

      It is somewhat objectively true:

      https://octoverse.github.com/2022/top-programming-languages

      https://github.blog/wp-content/uploads/2024/10/GitHub-Octove...

      It doesn't mean much, and this library can be reproduced in any of those top 10 languages from what I can tell.

      • simonask 3 hours ago
        Ruby will always have a special place in my heart. I cut my teeth as a young programmer on that language, and I learnt its value (as well as the value of using something else) along the way.

        Ruby code can be downright poetic, for better or worse. There's a certain kind of magic to the kind of code it enables. That's not always good, but it _is_ beautiful.

        I encourage everybody to read the venerable "Why's Poignant Guide to Ruby" [1] to see what I'm talking about.

        I wish Ruby was cross-platform. It still only works on Windows using the MSYS2 emulation layer, and the only reason as far as I can tell is that it committed hard and early to `fork()` as the main way to use multiple cores.

        [1]: https://poignant.guide/

      • nextos 5 hours ago
        Is position #10 in https://octoverse.github.com/2022/top-programming-languages bad?

        It ranks right after Shell (#8) and C (#9). Ruby is still a mainstream language, and it's fairly easy to find a Ruby job. Compare that to Clojure or Haskell.

        • josephg 4 hours ago
          Compare that to Rust. For all the hype it has, very few companies are shipping products with it. There are a few, but nowhere near as many as are using Ruby.
          • Lio 3 hours ago
            I get your point but it's a case of right tool for the job. Every copy of Ruby now includes YJIT written in Rust because Rust is the right tool for that task.

            It's easy to forget though that number of lines of code required to do something is also a valid metric and Ruby beats Rust on that.

            So if you're shipping CRUD web apps that might be a more important metric than say memory usage or CPU time.

            Different job, different tool. More people want to ship web apps than write their own JITs.

            Engineering is the art of trade offs.

          • IshKebab 1 hour ago
            Yeah but look at the trajectories - Rust is one of the fastest growing languages and Ruby is one of the fastest declining languages.
          • simonask 3 hours ago
            That's probably true, but also a poor measure of success. I bet there are more companies using Ruby than there are companies using C++, too. They fill different niches, and different types of companies deliver very different products using those languages.

            The ratio of people who can code in Python or Ruby to people who can code in Rust or C++ is very high.

            • jupp0r 3 hours ago
              I don’t know why “number of companies using language X” is a metric that is used here. Wordpress is serving 43% of websites on the internet as of 2025, so we should all be learning PHP!
          • jupp0r 3 hours ago
            You are probably writing this in a browser with Rust code in it.
        • someothherguyy 5 hours ago
          It has dropped in popularity and has never regained the popularity it once held.

          Of the many developers who used to write Ruby (myself included), I would wager not many of those same people still do.

  • jatins 8 hours ago
    Such a breath of fresh air compared to poor DX libraries like langchain
    • nullpoint420 8 hours ago
      I’ve found the Ruby community really cares about DUX. Not sure why it’s not in other language communities
      • toasterlovin 5 hours ago
        I don’t really mean this to be derogatory toward people who enjoy other things, but Ruby is a language and ecosystem by and for people who have taste.
        • continuational 4 hours ago
          Certainly a taste for global state, it seems.
          • IshKebab 1 hour ago
            Don't forget ungreppable code! And what are type hints anyway?
          • atemerev 4 hours ago
            Dogmatically rejecting global state even if it simplifies things in some particular case _is_ poor taste.

            Even a goto can be elegant sometimes.

            • zelphirkalt 3 hours ago
              Usually though it just creates long term issues, putting off important work to later.
              • bmacho 3 hours ago
                Sometimes later never comes, so it's a net win compared to languages where you are forced do this important work now.
      • choxi 8 hours ago
        Matz said he designed Ruby to optimize for developer happiness, it’s just a core principle of the language since it was created
        • kuboble 3 hours ago
          Happiness of a developer writing code can be a misery of a one having to read / debug it. I worked in ruby for a couple years around 2009 and having to deal with a code that implemented most of its logic via method missing is still one of the strongest negative memories I have about coding.
          • viraptor 2 hours ago
            Another annoying one from that category is Ruby's forwarded methods. Since they're created via generated, injected code, you can't query which method it forwards to at runtime. Or not easily anyway.
      • rochak 4 hours ago
        Umm, doesn’t Go do so as well? Personally, I’ve had a better experience working with Go tooling.
        • jatins 4 hours ago
          Go ecosystem is generally good. However, given that Go as a language doesn't have any "fancy" (for the lack of a better word) syntactical features you can't create DSL's like this

          though Ruby's expressiveness comes at a cost and I'd personally stick with Go in a team but use something like RubyLLM for personal projects

        • danenania 4 hours ago
          I'd say they both optimize for DX, but they come at it from very different angles. Ruby is focused on actually writing the code: making it feel expressive, intuitive, and fun.

          Go is more about making it easier to build fast and robust systems. But it really doesn't care if the code itself is ugly and full of boilerplate.

          As I've gotten more experience, I've come to really appreciate Go's tradeoffs. It's not as fun up front, but on the other hand, you're less likely to get server alerts at 4am. It really depends what you're building though.

    • olegp 6 hours ago
      Would anyone happen to know of a similar library with as good DX but for JavaScript or TypeScript?
    • ekianjo 8 hours ago
      langchain and llamaindex are such garbage libraries: not only they never document half of the features they have, but they keep breaking their APIs from one version to the next.
      • brokegrammer 1 hour ago
        I was about to mention those. I decided a while ago to build everything myself instead of relying on these libraries. We could use a PythonLLM over here because it seems like nobody cares about developer experience in the Python space.
    • someothherguyy 6 hours ago
      What about it is a breath of fresh air? What do the other libraries do that this doesn't?
  • antirez 2 hours ago
    The best Ruby always surpasses the elegance of the best Python... Unfortunately for practical means at this point I go for Python: more libraries, less problems with the C implementation of the interpreter (had issues with the GC in the past), better LLMs understanding of the code.
  • tommica 1 hour ago
    Wow the syntax is beautiful!
    • nextaccountic 1 hour ago
      That's my takeaway from Ruby - syntax matters, and good syntax makes programmers happier
  • FailMore 3 hours ago
    This looks amazing, is there anything one can do to change the system prompt where it is available?
  • jiangplus 5 hours ago
    I am writing some LLM-based app scripts, this feels like a breeze!
  • ketzo 7 hours ago
    Is this gonna be the thing that finally makes me tried Rails? Ruby syntax really is just nice.
    • drdaeman 7 hours ago
      I think it's the very nice-looking and clean high-level API that should be a pleasure to use (when it fits the job, of course).

      I'm pretty sure this API semantics (instance builder to configure, and then it's ask/paint/embed with language-native way to handle streaming and declarative tools) would look beautiful and easy to use in many other languages, e.g. I can imagine a similar API - save, of course, for the Rails stuff - in Python, C# or Erlang. While this level of API may be not perfectly sufficient for all possible LLM use cases, it should certainly speed up development time when this level of API is all that's possible needed.

  • aguynamedben 6 hours ago
    Ruby is alive and well!
  • ksec 7 hours ago
    Interesting cause I submitted this some time ago and I just did another one on

    https://news.ycombinator.com/item?id=43369977

    But it seems hashnode.dev as a domain is blocked entirely. Hopefully Ruby gets another chance in AI era.

  • init0 6 hours ago
    One of the most concise APIs to interact with an llm!

    Keep going! Happy to see ollama support PR in draft.

  • makuchaku 4 hours ago
    Abut time that someone built this in ruby! You rock!
  • ilrwbwrkhv 8 hours ago
    Oh just beautiful. Ruby is so expressive and concise.

    If you see the typescript options it's like giving yourself a water boarding session through your own volition.

  • kjgkjhfkjf 3 hours ago
    What are some similarly ergonomic packages for other languages?
  • Finbarr 6 hours ago
    This is a beautiful API. Thanks for the work. Here's hoping for a nice ruby agent framework in the near future too!
  • ultimoo 5 hours ago
    nice job! i miss using ruby.
  • freen 8 hours ago
    Wow. So thoughtful.

    Ruby: late to the party, brought a keg.

  • someothherguyy 6 hours ago
    Why does this say it was posted four hours ago on the front page, four days ago on Agolia, 3 days ago on /from and the comments are all from minutes to hours ago here?
    • noodletheworld 6 hours ago
      The threads have presumably been merged; look at the submitters in the history.

      > 166 points|ksec|4 days ago|21 comments

      > 168 points by ksec 4 hours ago

      But yes; it’s a bit dodgy to resurface old news like this imo and pretend it’s new news.

      I’d go as far as to say that being at #1, under the circumstances, means it’s been artificially boosted somehow.

      I haven’t the foggiest why anyone would bother though.

    • thinkingemote 3 hours ago
      at least 2 ways.

      1. Moderators can re-submit interesting stories from a second chance pool https://news.ycombinator.com/pool (This might happen automatically from time to time?) When this happens some of the timestamps get updated but others dont.

      2. Moderators can invite users via email to re-submit stories. https://news.ycombinator.com/invited

  • ripped_britches 6 hours ago
    This is an obviously fishy post!
  • tw1984 3 hours ago
    stone age LLM.
  • continuational 4 hours ago
    Why is it using a global variable for this?
    • t-writescode 3 hours ago
      It's not. The method, RubyLLM.chat creates a new instance of the Chat object, as has been copied here:

        module RubyLLM
          class Error < StandardError; end
      
          class << self
            def chat(model: nil)
              Chat.new(model: model)
            end
      
      https://github.com/crmne/ruby_llm/blob/9825f4fea089b1b974961...

      If you're wondering about module RubyLLM. That's just how Ruby is often written.

      Addendum: Ruby does not require you to put the opening and closing parenthesis on a function to run that function, and it's not always put there when you have zero or 1 parameter (I find it to be cleaner when you have a parameter, but have no opinion when there isn't a parameter)

      In the example code from the link itself, you'll see:

        chat.ask "What's the best way to learn Ruby?"
      
      which is the same as

        chat.ask("What's the best way to learn Ruby?")
      • bmacho 2 hours ago
        > Ruby does not require you to put the opening and closing parenthesis on a function to run that function, and it's not always put there when you have zero or 1 parameter

        mind = blown

        I always liked how functionName denotes the function and functionName() calls the function, and then it denotes the result e.g. in JavaScript or in math. But just saying functionName to call a function makes the code read more like English. Code that reads like English > code that reads like math. (And you can still talk about functions of course.)

        • tasuki 46 minutes ago
          You'd like the ML-family languages, which don't use parentheses to call functions.
        • viraptor 2 hours ago
          It comes with the downside that if you want to pass the function itself around, you need to do f=something.method(:the_function), and then f.call(args). It's not a huge deal, but... meh.
  • skavi 3 hours ago
    wow that looks super clean. i get why people build the world’s slowest web backends in this language now.
    • viraptor 2 hours ago
      It's not that slow really. Also, there's yjit included https://speed.yjit.org/

      We're running a few very popular services on rails and it's really not a problem in any way.