ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
<FromGitter> <Blacksmoke16> Correct
<FromGitter> <Blacksmoke16> Include is for modules, not classes
ur5us_ has quit [Ping timeout: 256 seconds]
debayer has joined #crystal-lang
ur5us_ has joined #crystal-lang
ua_ has joined #crystal-lang
csk has joined #crystal-lang
csk has quit [Client Quit]
watsy0007 has joined #crystal-lang
notzmv has quit [Ping timeout: 248 seconds]
watsy0007_ has joined #crystal-lang
watsy0007 has quit [Client Quit]
watsy0007_ has left #crystal-lang [Textual IRC Client:]
watsy0007 has joined #crystal-lang
watsy0007 has quit [Ping timeout: 268 seconds]
* FromGitter * tenebrousedge hates interviews, and especially algorithmic problems
<FromGitter> <Blacksmoke16> ```code paste, see link``` []
<FromGitter> <Blacksmoke16> interesting that this prints both `Child1` and `Child2` 🤔
<FromGitter> <Blacksmoke16> seems like it's expanding to `pp(type) if == "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?
<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> <Blacksmoke16> 👍
debayer has quit [Quit: Textual IRC Client:]
<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:
<hightower2> REG1 = /test/; REG2 = /^test$/ ?
<straight-shoota> REG2 = /^#{REG1}$/
<straight-shoota> but that's it
<hightower2> ok, thank you
<straight-shoota> Maybe might be interesting for this use case
<straight-shoota> feel free to leave a comment there
ur5us_ has quit [Ping timeout: 252 seconds]
Starfoxxes has joined #crystal-lang
<raz> why do i even try anymore 🤷
ur5us_ has joined #crystal-lang
<raz> ha, it works
<raz> a bit surprised it does actually, but not complaining lol
hightower2 has quit [Ping timeout: 248 seconds]
Guest81 has joined #crystal-lang
Guest81 has quit [Client Quit]
avane has quit [Quit: o/]
avane has joined #crystal-lang
ur5us_ has quit [Ping timeout: 256 seconds]
ur5us_ has joined #crystal-lang
fifr[m] has quit [Ping timeout: 240 seconds]
jhass[m] has quit [Ping timeout: 256 seconds]