ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
Stephie has joined #crystal-lang
Vexatos has quit [Ping timeout: 265 seconds]
Stephie- has quit [Ping timeout: 265 seconds]
Vexatos_ has joined #crystal-lang
Vexatos_ has quit [Ping timeout: 245 seconds]
Stephie has quit [Ping timeout: 245 seconds]
Stephie has joined #crystal-lang
Vexatos has joined #crystal-lang
Stephie has quit [Quit: Fuck this shit, I'm out!]
Vexatos has quit [Read error: Connection reset by peer]
Stephie has joined #crystal-lang
Vexatos has joined #crystal-lang
Stephie has quit [Read error: Connection reset by peer]
Stephie has joined #crystal-lang
Vexatos_ has joined #crystal-lang
Vexatos has quit [Ping timeout: 245 seconds]
ur5us_ has quit [Ping timeout: 245 seconds]
Vexatos_ has quit [Quit: Client Quit]
Vexatos has joined #crystal-lang
ur5us_ has joined #crystal-lang
deavmi has quit [Ping timeout: 252 seconds]
deavmi has joined #crystal-lang
ur5us_ has quit [Quit: Leaving]
ur5us has joined #crystal-lang
Chillfox has quit [Ping timeout: 260 seconds]
Chillfox has joined #crystal-lang
ur5us has quit [Ping timeout: 245 seconds]
notzmv has quit [Ping timeout: 265 seconds]
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
adam124 has joined #crystal-lang
adam12 has quit [Ping timeout: 265 seconds]
adam124 is now known as adam12
notzmv has joined #crystal-lang
Chillfox has quit [Quit: Leaving]
taupiqueur has joined #crystal-lang
taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
Volk has joined #crystal-lang
Volk has quit [Changing host]
Volk has joined #crystal-lang
<FromGitter> <syeopite:matrix.org> Could the following be transformed into a case statement? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=615ecfdfcd4972068b336b35]
<FromGitter> <erdnaxeli:cervoi.se> i don't think that's possible
<FromGitter> <erdnaxeli:cervoi.se> you can do this but it is not very useful: https://carc.in/#/r/c0ee
<FromGitter> <skinnyjames> Hi all, ⏎ I'm looking for a way to customize converting an object into JSON. ⏎ given a constructor like this ⏎ ⏎ ```code paste, see link``` ... [https://gitter.im/crystal-lang/crystal?at=615ee25ad3ae402e4735357b]
<FromGitter> <naqvis> you can go with custom generating json via JSON.build (https://crystal-lang.org/api/1.1.1/JSON.html#generating-with-json.build)
<FromGitter> <skinnyjames> ah, is there a way to pass state from the subclass to the super? ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ results in malformed json [https://gitter.im/crystal-lang/crystal?at=615ee95438377967f43b440d]
<FromGitter> <naqvis> you can simplify this branching with ⏎ ⏎ ```inner = outer["a"]? || outer["b"]? || outer["c"]? || outer["d"]``` [https://gitter.im/crystal-lang/crystal?at=615ee97aa41fd20699cd5c92]
<FromGitter> <jrei:matrix.org> Yes and a bit less efficient
<FromGitter> <syeopite:matrix.org> And more verbose than the if-block unfortunately.
<FromGitter> <syeopite:matrix.org> Ooh haven't thought of that. Though that's only great for short keys; any longer then it gets pretty unreadable
<FromGitter> <jrei:matrix.org> the if/eslif is good
<FromGitter> <jrei:matrix.org> you can do as @naqvis said, but then you can't define a specific logic for each key
<FromGitter> <syeopite:matrix.org> It works but it's quite verbose imo. Especially for longer chains like what Invidious often uses; being able to condense that into a case statement would be great
<FromGitter> <naqvis> you are doing it right, but passed `data` is actually a json object, not a simple field. so you need to change `json.field "#{@options_key}"` to `json.object`
<FromGitter> <syeopite:matrix.org> True. Haven't thought of that caveat
<FromGitter> <skinnyjames> I think data in this case is a generate dstring
<FromGitter> <skinnyjames> "{\"capabilities\":\"alwaysMatch\",\"browserName\":\"firefox\",\"moz:firefoxOptions\":\"{\\\"binary\\\":\\\"/usr/lib/firefox/firefox\\\"}\"}" is the result.. So the data is stringified twice. ⏎ ⏎ I tried to pass a String::Builder to the superclass but that results in infinite recursion
<FromGitter> <jrei:matrix.org> Another way: https://carc.in/#/r/c0ej
<FromGitter> <naqvis> generated json in string format. as generated string would be something like `"binary": "blah blah blah"`
<FromGitter> <skinnyjames> "{\"capabilities\":\"alwaysMatch\",\"browserName\":\"firefox\",\"moz:firefoxOptions\":\"{\\"binary\\":\\"/usr/lib/firefox/firefox\\"}\"}" is the result.. So the data is stringified twice. ⏎ ⏎ I tried to pass a String::Builder to the superclass but that results in infinite recursion
<FromGitter> <Blacksmoke16> is that you doing `pp ob.json`?
<FromGitter> <Blacksmoke16> try `puts`
<FromGitter> <skinnyjames> nice! I was doing that, and removed all pp refs, but I'm still getting output for some reason: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=615eecfcf2cedf67f970076b]
<FromGitter> <skinnyjames> ```code paste, see link``` ⏎ ⏎ Lots o output [https://gitter.im/crystal-lang/crystal?at=615eed31fb3dcd4e8812b620]
<FromGitter> <Blacksmoke16> can you make a playground link with your code rq?
<FromGitter> <skinnyjames> yeah for sure
<FromGitter> <skinnyjames> https://play.crystal-lang.org/#/r/c0eq ⏎ ⏎ the data string is double escaped ⏎ noticed i have a different issue with the payload though, as I don't know how to spin up a new object as a the value of a field [https://gitter.im/crystal-lang/crystal?at=615ef06838377967f43b54e8]
<FromGitter> <Blacksmoke16> and you're wanting to store a JSON string as the value of the options key yea?
<FromGitter> <Blacksmoke16> versus its own full object?
<FromGitter> <skinnyjames> ideally it'd be cool to pass an object that gets embedded and stringified with the rest
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/c0ev is what i came up with
<FromGitter> <skinnyjames> @naqvis thanks! i was wondering how to use raw
<FromGitter> <skinnyjames> @Blacksmoke16 this is awesome and ideal
<FromGitter> <Blacksmoke16> feels a bit more idiomatic than the custom `#json` method and more OOP style
<FromGitter> <skinnyjames> my last question is that I was trying to get a string that was ⏎ { "capabilities": { "alwaysMatch": etc...}} ⏎ instead of ⏎ ⏎ {"capabilities": "alwaysMatch"} ... [https://gitter.im/crystal-lang/crystal?at=615ef3ecfb3dcd4e8812c7d5]
<FromGitter> <Blacksmoke16> got the full expected json string?
<FromGitter> <Blacksmoke16> just missing some `json.object`
<FromGitter> <skinnyjames> {"capabilities": { "alwaysMatch": { ,"browserName":"firefox","moz:firefoxOptions":{"binary":"/user/bin/firefox/firefox"}}}}
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/c0ez
<FromGitter> <skinnyjames> ah, makes sense! thanks!
hightower2 has joined #crystal-lang
hightower2 has quit [Ping timeout: 245 seconds]
jhass[m] has quit [Ping timeout: 260 seconds]
jhass[m] has joined #crystal-lang
dostoyevsky2 has quit [Ping timeout: 252 seconds]
dostoyevsky2 has joined #crystal-lang
Volk has quit [Quit: See you next time!]
ur5us has joined #crystal-lang
kiwiroy has quit [Ping timeout: 240 seconds]
r0bby has quit [Ping timeout: 240 seconds]
kevinsjoberg has quit [Ping timeout: 260 seconds]
pusewic|away has quit [Ping timeout: 250 seconds]
Liothen has quit [Ping timeout: 250 seconds]
Liothen has joined #crystal-lang
r0bby has joined #crystal-lang
pusewic|away has joined #crystal-lang
kevinsjoberg has joined #crystal-lang
kiwiroy has joined #crystal-lang
Volk has joined #crystal-lang
Volk has quit [Changing host]
Volk has joined #crystal-lang
<FromGitter> <plambert> I'm trying to read a CSV file that has a BOM (byte order mark) as the first three bytes. Even if I read the bytes off the IO before giving it to CSV, it seems to start at the beginning of the file. Any idea how I can either make it skip them, or keep it from rewinding before reading the headers?
<FromGitter> <plambert> I can't find a `rewind` or `seek` in the CSV library code... but it still says the first quote is unexpectedly in the middle of the cell.
<FromGitter> <plambert> Or maybe I can make an `IO::BOM` class that skips them and never lets the user seek over them... Hmmm...
<riza> Dang, I expected this to work... https://carc.in/#/r/c0gy
<riza> well, maybe for my usage it can just be inherited instead of included...
<FromGitter> <Blacksmoke16> why would you expect that to work?
<riza> maybe that's incorrect documentation, but it seems to say you can type an array with the name of a module - A - and then shift instances of classes which include that module into the array
<FromGitter> <Blacksmoke16> but thats now what you're doing
<FromGitter> <Blacksmoke16> not*
<riza> sure but if you can type an Array with it, why cant you type a variable with it
<riza> A.class doesn't work -- it's not a class
<FromGitter> <Blacksmoke16> it would work if you did `Bar.new(Foo.new)`
<FromGitter> <Blacksmoke16> because it's expecting an instance of something that includes that type
<riza> yep, but I don't see a way around that which isn't pivoting over to inheritance
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> https://carc.in/#/r/c0ha
<riza> incidentally I also expected this to be a thing: https://crystal-lang.org/api/1.1.1/Module.html
<FromGitter> <Blacksmoke16> depending on the use case, inheritance might make more sense. but hard to say w/o knowing the rest of the context of what you're wanting to do
<FromGitter> <Blacksmoke16> sec, i have a better iea
<FromGitter> <Blacksmoke16> idea
ur5us has quit [Ping timeout: 252 seconds]
<riza> yeah, I don't think inheritance is a bad choice for me here. It boxes you in a bit where you can't inherit from other sources so I don't reach for it as my first goto
<riza> that's an interesting approach...it feels a bit of a hack
<FromGitter> <Blacksmoke16> the question i always ask myself when figuring out what to do: Do you want to support *both* structs and classes?
<FromGitter> <Blacksmoke16> if the answer is yes, you need to use a module
<riza> Hm, I don't think that's material in this case. I worry that I might need to subclass some unknown other class as well, and now I have multiple inheritance problems.
<FromGitter> <Blacksmoke16> can you share more of what you're wanting to do?
<riza> it's weird to me that `macro ItWorksClass` can be used as a type. I didn't expect that to work either
<FromGitter> <Blacksmoke16> 🤔 thats prob bug
<riza> hah
taupiqueur has quit [Ping timeout: 245 seconds]
<riza> the goal is to provide an interoperability layer -- a Type which can be used to declare both static and instance methods, and I want to stash the Type in a config var so the library can dereference the Type with calls like Lib.interop.do_thing and Lib.interop.new(config).do_stuff
<riza> I think for this case inheritance works fine, but I'm still surprised that there isn't a way to do this without
<riza> sorry, i totally losttrack of time and have to run
<riza> thanks for looking Blacsmoke
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/c0he
<FromGitter> <Blacksmoke16> could do something like that? :shrug:
<FromGitter> <Blacksmoke16> o/
Volk has quit [Ping timeout: 260 seconds]
Chillfox has joined #crystal-lang