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
jhass has quit [Ping timeout: 248 seconds]
straight-shoota has quit [Ping timeout: 252 seconds]
jhass has joined #crystal-lang
straight-shoota has joined #crystal-lang
ur5us has quit [Ping timeout: 248 seconds]
<FromGitter> <mane:arcticfoxes.net> Is scoop on windows good enough to run crystal playground or should i play it safe and use wsl?
lanodan has quit [Ping timeout: 252 seconds]
lanodan has joined #crystal-lang
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
_ht has joined #crystal-lang
Vexatos has left #crystal-lang [Diffusing]
Vexatos has joined #crystal-lang
quazimodo has quit [Ping timeout: 252 seconds]
HumanG33k has quit [Quit: WeeChat 3.0]
HumanG33k has joined #crystal-lang
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
madprops has left #crystal-lang [Leaving]
jmdaemon has quit [Ping timeout: 248 seconds]
jmdaemon has joined #crystal-lang
jmdaemon has quit [Ping timeout: 255 seconds]
jmdaemon has joined #crystal-lang
hightower3 has quit [Remote host closed the connection]
hightower3 has joined #crystal-lang
hightower3 has quit [Ping timeout: 264 seconds]
jmdaemon has quit [Ping timeout: 252 seconds]
hightower2 has joined #crystal-lang
jmdaemon has joined #crystal-lang
jmdaemon has quit [Ping timeout: 268 seconds]
<FromGitter> <Blacksmoke16> prob easy enough to find out, worst case go the wsl route
<FromGitter> <revskill10> Hi everyone, i have abstract class, which use `json_discrimination`, my question is, how the `from_json` work in this case ?
<FromGitter> <Blacksmoke16> youd just use it on the abstract class
<FromGitter> <Blacksmoke16> and il'll know which subclass to instantiate based on the discriminator
<FromGitter> <revskill10> @Blacksmoke16 It said `Error: can't instantiate abstract struct`
<FromGitter> <Blacksmoke16> and thats from you doing `.from_json` or `.new`?
<FromGitter> <revskill10> ```code paste, see link``` ⏎ ⏎ This is how i call [https://gitter.im/crystal-lang/crystal?at=63dd4393747c6938e1fe6930]
<FromGitter> <Blacksmoke16> and `Event` is the class that calls/uses `json_discrimination`?
<FromGitter> <revskill10> Event is an abstract struct
<FromGitter> <revskill10> yeah
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/cr got an example?
<FromGitter> <revskill10> https://play.crystal-lang.org/#/r/ei7e
<FromGitter> <Blacksmoke16> okay yea, you're not using `use_json_discriminator` correctly
<FromGitter> <Blacksmoke16> it should be defined on the abstract parent type only
<FromGitter> <Blacksmoke16> e.g. https://crystal-lang.org/api/JSON/Serializable.html#use_json_discriminator%28field%2Cmapping%29-macro
<FromGitter> <revskill10> @Blacksmoke16 ahh, i got it. ⏎ I want to auto json discriminator when subclassing, is it possible ? ⏎ It works fine with `to_json`
<FromGitter> <Blacksmoke16> something like https://play.crystal-lang.org/#/r/ei7j maybe?
<FromGitter> <revskill10> @Blacksmoke16 it's weird, when i `puts typeof(Event.from_json(new_json)` , it said `Event` instead of `Completed` ?
<FromGitter> <Blacksmoke16> its not wrong
<FromGitter> <Blacksmoke16> compiler cant know what specific runtime type will be instantiated based on the JSON, so it says `Event` since they're all children of that type
<FromGitter> <revskill10> How to check if runtime type is `Completed`
<FromGitter> <Blacksmoke16> for debugging or?
<FromGitter> <revskill10> Just a question for runtime version of `typeof` ?
<FromGitter> <Blacksmoke16> `.class`
<FromGitter> <revskill10> Thanks ! So much magic in your code. Do you have detail guide on those magics ?
<FromGitter> <revskill10> One question, what's the idiomatic way for error handling for `from_json` ? Should i create another `safe_from_json` with a rescue (and return Nil)` or let caller do it ?
<FromGitter> <Blacksmoke16> let the caller do it id say
<FromGitter> <revskill10> @Blacksmoke16 thanks for the guidance. This JSON part of crystal beats other programming language in a clean way to me ! So clean, safe and DRY !
__ht has joined #crystal-lang
_ht has quit [Ping timeout: 248 seconds]
__ht is now known as _ht
<FromGitter> <wwalker> I want to include some lua scripts (fairly long) in crystal as a string. But I'd like to have them in separate files, so that I can edit/test them as Lua files. ⏎ ⏎ Is there something like C's #include in crystal?
<FromGitter> <Blacksmoke16> as strings assigned to a const or?
<FromGitter> <wwalker> either one. Should likely be a constant, as it will never be modified by crystal
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/Crystal/Macros.html#read_file(filename):StringLiteral-instance-method
<FromGitter> <wwalker> Thank you!
jmdaemon has joined #crystal-lang
hightower2 has quit [Ping timeout: 248 seconds]
hightower2 has joined #crystal-lang
ur5us has joined #crystal-lang
<FromGitter> <revskill10> @Blacksmoke16 could you help fix this code ? ⏎ https://play.crystal-lang.org/#/r/ei8g ⏎ It's valid Ruby code, just want to port it to Crystal with same semantic.
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/ei8i
<FromGitter> <Blacksmoke16> what are you expecting this to output? 50 or?
<FromGitter> <Blacksmoke16> er it would be `include WithLog`
<FromGitter> <Blacksmoke16> but still dont think this is going to do what you want it to
<FromGitter> <revskill10> @Blacksmoke16 expectation is it output original `50` with a log string
<FromGitter> <Blacksmoke16> idt thats possible without making more changes
<FromGitter> <revskill10> So the idea , is you decorate original method for only one object instead of all instance of the class.
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/ei8p can do it this way
<FromGitter> <Blacksmoke16> yea pretty sure you're going to have to go to plan b
_ht has quit [Quit: _ht]
ur5us has quit [Ping timeout: 260 seconds]
Sankalp- has joined #crystal-lang
Sankalp has quit [Ping timeout: 252 seconds]
Sankalp- is now known as Sankalp