3 ms·
> def execute(path:) > why the "incomplete" colon? Just ruby's syntax to denote 'keyword arguments', i.e. when calling this method, you must explicitly use th
by nomilk 1y ago
> def execute(path:)
> why the "incomplete" colon?
Just ruby's syntax to denote 'keyword arguments', i.e. when calling this method, you must explicitly use the parameter name, like so: execute(path: "/some/path")
> class ListFiles < RubyLLM::Tool
> what's with the "<"?
Just ruby's way of denoting inheritance i.e. class A < B means class A inherits from B
> param :command, desc: "The command to execute"
> again, the colons are confusing...
The colons can be confusing, but you get used to them. The first one in :command is denoting a symbol. You could think of it as just a string. Any method that expects a symbol could be rewritten to uses a string instead, but symbols are a tad more elegant (one less keypress). The second one, desc:, is a keyword argument being passed to the param method. You could rewrite it as param(:command, desc: "The command to execute")
I sometimes wonder what ruby would be like without symbols, and part of me thinks the tradeoff would be worth it (less elegant, since there'd be "strings" everywhere instead of :symbols, but it would be a bit easer to learn/read.
- deleted 1y ago[deleted]
- d4mi3n 1y agoAnother couple important aspects of symbols: 1. They refer to the same object in memory, so multiple usages of a symbol by the same name (e.g. `:param`) not not add additional memory overhead. 2. Symbols are also immutable in that they cannot be mutated in any way once they are referenced/created. These properties can be useful in some contexts, but in practice they're effectively used as immutable constant values.
- jbverschoor 1y agoI disagree. symbols are constants, and strings are text. Very clear distinction, relevant when you have syntax highlighting. Working with json/xml, or anything that has keys and text-values for that matter is a lot better with symbols