Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?")


> 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.)


You'd like the ML-family languages, which don't use parentheses to call functions.


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.


But in general, ruby code only passes anonymous functions and, in those cases, the syntax is beautiful.


You might know this, but you can also do f.(args) or f[args] in the latter case. It's still a bit meh, but slightly less verbose.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: