billyruffian has quit [Remote host closed the connection]
<FromGitter>
<bovepm> hi there! former rubyist and crystal newbee here. I am currently writing some crystal code and wanted to use the mixin Enumerable on class level rather than on instance level (see code below). any hints? ⏎ https://carc.in/#/r/bc7v
<FromGitter>
<bovepm> super, thanks for the quick reply
fifr has quit [Changing host]
fifr has joined #crystal-lang
dostoyevsky2 has quit [Quit: leaving]
dostoyevsky2 has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
ua_ has joined #crystal-lang
<FromGitter>
<foxxx0> Hi, any suggestions on how I would best implement a predefined set of format strings / placeholders that can be user-specified (e.g. via config file)? I don't want allow users to directly influence the `#sprintf` formatstring for security reasons, I was thinking more in the direction of having something like `"some prefix: ###foo.attr1### with ###foo.attr2###"` where I want to replace `"###foo.attr1###"` with
<FromGitter>
... the value of `foo.attr1` and so on. How could achieve that somewhat elegantly?
<FromGitter>
<naqvis> @foxxx0 Crystal doesn't support RTTI, that means there is no way to achieve dynamic execution of props/methods. Crystal expects methods/fields calls to be known at compile time. What I understand from your context is you are looking for some template language which you can invoke at run-time
<FromGitter>
<foxxx0> mh, looks like crinja strictly expects values and not custom classes
<FromGitter>
<foxxx0> maybe i'll need to parse the user-supplied argument then and provide crinja with the correct value? but then there is no point to pulling in crinja
<FromGitter>
<naqvis> hmm, how come such conclusion?
<FromGitter>
<naqvis> Template engine doesn't force you to any specific set of usage
<FromGitter>
<naqvis> you can access any object as long as template engine has access to that object
<FromGitter>
<Blacksmoke16> try and use `__DIR__` instead of `.`
<FromGitter>
<Blacksmoke16> pretty sure `.` is the dir you're executing the file from while `__DIR__` is the location of the file or something like that
wmoxam_ is now known as wmoxam
<FromGitter>
<Blacksmoke16> oh but try doing ` ECR.def_to_s "#{ECR_ROOT.id}/greeter.ecr"`
<FromGitter>
<speg> same thing, I had also tried using `Dir.current` with no luck
<FromGitter>
<speg> ooh, `.id`?
<FromGitter>
<Blacksmoke16> yea
<FromGitter>
<speg> Success! 🙌🏼 Thank you sir. I haven't used macros yet, what's going on here?
<FromGitter>
<Blacksmoke16> seems like its interoplating the string literal into the other string. Notice the path in the error has like `\"`, instead of just like `ecr/greeter.ecr`
<FromGitter>
<Blacksmoke16> `.id` returns the raw value of the constant, e.g. `./src/template/components/ecr`
<FromGitter>
<Blacksmoke16> *maybe* thats a bug as it's deff not what you'd expect :shrug:
<FromGitter>
<speg> hehe, neat. I was reading up on macros just last night but obvs need to learn some more. Thanks again!
<FromGitter>
<wyhaines> It has some limitations that I haven't bothered to address yet (and some that can not be fixed), and caveat emptor re undiscovered bugs, but basically it lets one do dynamic dispatch to objects in Crystal.
<FromGitter>
<wyhaines> Feel free to ping me here or on Github or on the discord if you have any questions about what you can or can not do with it, or if it does something that you think is broken.
<FromGitter>
<Blacksmoke16> I'd guess`Crypto` already exists and is nodoc
dom96_ is now known as dom96
<FromGitter>
<didactic-drunk> I don't see defined `Crypto`anywhere. It's implicitly defined as `Crypto::{Subtle,Bcrypt,Blowfish}`
<FromGitter>
<oprypin:matrix.org> @didactic-drunk: because `Crypto` (https://crystal-lang.org/api/1.0.0/Crypto.html) is marked as originating from stdlib by its first occurrence in the whole code blob, and the whole stdlib is excluded from doc building
<FromGitter>
<didactic-drunk> @oprypin:matrix.org Now I have a workaround. Thank you
<FromGitter>
<oprypin:matrix.org> @didactic-drunk: im scared. what is it?