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
<FromGitter> <asnewman> Hello! New to Crystal. Would someone be able to answer my (simple) Stack Overflow question? https://stackoverflow.com/questions/73239448/adding-a-nilable-variable-to-a-non-nilable-array
<FromGitter> <Blacksmoke16> looks like it already was
<FromGitter> <Blacksmoke16> `typeof` and `==` isnt the way to the reduce the type of a variable
<FromGitter> <Blacksmoke16> that's more suited to `.is_a?` among others
<FromGitter> <Blacksmoke16> but in this case you could prob just do like ⏎ ⏎ ```if new_task ⏎ current_todos << new_task ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=62ec682f72ad51741fd4ba4f]
<FromGitter> <Blacksmoke16> or even just push the task directly in the parser via like `current_todos << task`
<FromGitter> <Blacksmoke16> which you'd have to do if you want to be able to add more than one thing, otherwise `new_task` will just be set to the last value you add
<FromGitter> <Blacksmoke16> and correction, you cant just do `if new_task`. iirc something with the way option parser works and how the var is closured or something
<FromGitter> <asnewman> Yeah for some reason the answer on the SO question was still resulting in the same error 🤔
<FromGitter> <Blacksmoke16> yea it relates to the way option parser works. the value is closured by the `#on` method. compiler doesnt know when/if it'll be called, or what value will be assigned to it. so it keeps nil in the union
<FromGitter> <Blacksmoke16> in this case could just do like `current_todos << new_task.not_nil!`, but better to just handle this directly in the on method so it properly handles multiple tasks
<FromGitter> <asnewman> Ah I see. You're right, when I removed the parser section and simply did this it worked: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=62ec6a363a42316d33e47693]
<FromGitter> <Blacksmoke16> yea, in this case you dont even need the if. the compiler can figure out that it'll always be a string
<FromGitter> <asnewman> Great, that works. Thanks for the help!
<FromGitter> <Blacksmoke16> 👍 np
Liothen has quit [Read error: Connection reset by peer]
Liothen has joined #crystal-lang
renich has quit [Quit: Leaving]
Vexatos_ has quit [Ping timeout: 255 seconds]
Stephie has quit [Ping timeout: 252 seconds]
Stephie has joined #crystal-lang
Vexatos has joined #crystal-lang
Flipez has quit [Read error: Connection reset by peer]
Flipez has joined #crystal-lang
Flipez has quit [Changing host]
Flipez has joined #crystal-lang
jmd_ has quit [Ping timeout: 268 seconds]
Sankalp has quit [Ping timeout: 240 seconds]
Sankalp has joined #crystal-lang
hightower4 has joined #crystal-lang
hightower3 has quit [Ping timeout: 240 seconds]
hightower4 has quit [Remote host closed the connection]
hightower4 has joined #crystal-lang
hightower4 has quit [Ping timeout: 240 seconds]
Sankalp has quit [Ping timeout: 252 seconds]
Sankalp has joined #crystal-lang
irc_user has joined #crystal-lang
riza has quit [Quit: riza]
jmdaemon has joined #crystal-lang
jmd_ has joined #crystal-lang
jmdaemon has quit [Ping timeout: 252 seconds]
irc_user has quit [Quit: Connection closed for inactivity]