<FromGitter>
<Blacksmoke16> interesting that this prints both `Child1` and `Child2` 🤔
<FromGitter>
<Blacksmoke16> seems like it's expanding to `pp(type) if type.name.stringify == "Child1"` which is true in both cases because its an expression versus using the resulting value
ua_ has quit [Ping timeout: 248 seconds]
ua_ has joined #crystal-lang
ur5us_ has quit [Ping timeout: 256 seconds]
watsy0007 has joined #crystal-lang
watsy0007 has quit [Client Quit]
<raz>
tenebrousedge: to make this realistic we will now simulate an average workday situation. please write us a bubble-sort. here is your pencil. you have 5 minutes and we will stare at you in the meantime.
<raz>
hmm. is there a way to inherit a mixture of instance- and class-methods from a module? https://carc.in/#/r/bqyv
<raz>
it seems i can only choose between getting all def's as instance methods (include), or as class methods (extend)
<FromGitter>
<Blacksmoke16> i think you'd be best off in defining another module within your module like `module ClassMethods`
<FromGitter>
<Blacksmoke16> then have a `macro included` hook that does `extend ClassMethods`
<raz>
uff. nice, that might indeed work
<raz>
i was already preparing my reply to "why not use an abstract struct" (-> because the target struct already extends one)... but as usual you're one step ahead lol
<raz>
s/extends/inherits from one/
<FromGitter>
<Blacksmoke16> solution there would be to abstract the parent one into a base type, then inheit from that for your normal struct that would basically be empty
<FromGitter>
<Blacksmoke16> then inherit from the base again for this struct
<raz>
yup, with the ClassMethods-module trick it should work
<FromGitter>
<jwaldrip> Not much but its something
<FromGitter>
<jwaldrip> In our monorepo
yxhuvud has quit [Read error: Connection reset by peer]
yxhuvud has joined #crystal-lang
hightower2 has joined #crystal-lang
<hightower2>
Hey if I have a commonly used regex, like /\x1b\[[\d;]*m/ , what's a good way to define that as some sort of a constant that I can later use not only as-is but also slightly modified (e.g. with ^ or $ modifiers, and as part of a look-ahead/look-behind) ?
<FromGitter>
<Blacksmoke16> did you try defining it as a const then do like `
<FromGitter>
<Blacksmoke16> `/^#{BASE}/`
<hightower2>
I thought of defining it as a constant, like REGEX = /.../, but is that the best way, given that I don't know how I'd reuse that efficiently if ^$ need to be added
<hightower2>
right, I thought of that but thought #{...} was not very optimal? (Wouldn't it expand every time?)
<hightower2>
s/expand/expand and recompile the regex/
notzmv has joined #crystal-lang
<FromGitter>
<Blacksmoke16> not sure
ua_ has quit [Ping timeout: 268 seconds]
ua_ has joined #crystal-lang
ur5us_ has joined #crystal-lang
<straight-shoota>
If you assign it to a constant or variable, it's not going to be recompiled
<hightower2>
straight-shoota, even though it appears later in something like /^#{CONST}$/ ?
<hightower2>
like, REGEX = /abc/; if str.matches? /^#{REGEX}$/ ?
<straight-shoota>
No, you need to assign the expanded expression to another constant (or variable): `REGEX_LINE = /^#{REGEX}$/`
<straight-shoota>
Regex instances created from literals are only cached if they contain no interpolation
<hightower2>
OK, thanks. So bottom line, is there any more convenient way than defining 2 very similar constants for a slightly different regex, like: