<FromGitter>
<hybls_twitter> hey guys, quick question: Where can I find a list of crystal's built-in types (UInt32, String, Char, etc.) I'm having a hard time finding it.
<FromGitter>
<hybls_twitter> Ah, nevermind. I found what I was looking for.
<FromGitter>
<Blacksmoke16> wouldnt be *as* bad if both `Generic` and `Union` had a `types` method
<FromGitter>
<Blacksmoke16> vs `types` and `types_vars`
<FromGitter>
<Blacksmoke16> then could prob do something like `arg.restriction.is_a?(Path) ? arg.restriction.resolve.nilable? : arg.restriction.types.any? { |t| t.resolve.nilable? }`
<FromGitter>
<Sija> although it’s weird ‘cause there’s `TypeNode#nilable?` which should work inside macros...
moei has quit [Ping timeout: 246 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<Blacksmoke16> ikr? i was attempting to add the `#nilable?` to `Union` yesterday and i was doing like `BoolLiteral.new(@types.any? { |t| t.nilable? })` and was saying `no method #nilable?` exists on TypeNode`
<FromGitter>
<Blacksmoke16> wait, hows that work? just by adding `()`?
<FromGitter>
<Blacksmoke16> oh, are doing it at runtime now
Groogy has quit [Quit: WeeChat 2.3]
<FromGitter>
<Blacksmoke16> works well enough for my needs
spacemanspam has joined #crystal-lang
<FromGitter>
<Sija> yep, runtime to the rescue...
<FromGitter>
<Blacksmoke16> well, now i just need to write docs
sagax has quit [Ping timeout: 258 seconds]
simerax has joined #crystal-lang
<simerax>
How can I initialize a Hash with values? Apparently you can invoke Hash.new with a Block. However I don't quite get how I could invoke that block as some kind of iterator. Lets say I would like to create a Hash which holds each Letter of the alphabet as a key and the Numeric value of that Letter as Value. How could I achieve something like that?
<simerax>
I don't seem to find any example of that
<simerax>
i did not think about the to_h method. i thought you would usually do it with Hash.new
<simerax>
^^
Groogy has quit [Quit: WeeChat 2.3]
Groogy has joined #crystal-lang
spacemanspam has quit [Read error: Connection reset by peer]
gangstacat has quit [Quit: Ĝis!]
gangstacat has joined #crystal-lang
<simerax>
@Sija i have another question regarding the method you showed me to initialize the hash. In my Class i defined @alphabet as Hash(Char, Int32). However @alphabet = ('A'..'Z').map { |char| [char, char.ord] }.to_h does not compile. Error Message is: instance variable '@alphabet' of Message must be Hash(Char, Int32), not Hash(Char | Int32, Char | Int32). Why does this create union types?
<FromGitter>
<Sija> because elements of an `Array` are always an `Union` of all possible types
<simerax>
Well and how could i then create a true Hash(Char,Int32) ?
<FromGitter>
<Sija> I’ve updated my example to use `Tuple`s instead but the IRC bridge doesn’t show updates obviously
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
sagax has quit [Ping timeout: 246 seconds]
<FromGitter>
<vladfaust> I think that gitter integration with github is broken
sagax has joined #crystal-lang
DTZUZO has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<Sija> I’ve just stumbled upon the fact that you can’t use lazy getters with `Bool` since `||=` operator will (incorrectly in this case) run lazy macro for `false` values
<FromGitter>
<Sija> should it be changed to check for `.nil?` instead? whatcha think? /cc @asterite @bcardiff @ysbaddaden @straight-shoota
<FromGitter>
<Sija> @vladfaust seems like it
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter>
<j8r> you can't too with the `if var = nillable_bool` and `nillable_bool ? ... : ...`
<FromGitter>
<j8r> it's consistent
<FromGitter>
<Sija> @j8r I’m talking about lazy getters, not conditionals...
<FromGitter>
<Blacksmoke16> also modularized everything so if you can only require what you want/need
<FromGitter>
<Blacksmoke16> 💯
<FromGitter>
<girng> nice blacksmoke
<FromGitter>
<girng> i think i found a bug in the db module with NULL lol. if you check the "NULL" box in adminer for your mysql column, when reading that data from the query you'll get some can't cast nil to {whatever}. i even tried `{type: Int64, nilable: true}` in the DB.mapping, but i think nilable is different than nullable? i don't know LMAO ⏎ ⏎ but, i did just uncheck the "NULL" checkbox in adminer, and the Int64
<FromGitter>
... default's to 0, which works fine
<FromGitter>
<Blacksmoke16> <3
<FromGitter>
<j8r> @Sija but you're talking about changing the `||=` behavior?
<FromGitter>
<Sija> @j8r I’m talking about lazy getters with `Bool` types
<FromGitter>
<Nbotz> Hello all, anyone know of a good way to dynamically add/read to/from a crystal file?
<oprypin>
you'll have to explain what you're trying to achieve by that
<FromGitter>
<Nbotz> I have a set of images in a folder, and i want a gallery to display information of the picture as well as the picture itself. I have a .cr file that consists of an array. the array has hashes that have the information of the images, aswell as the image location
<FromGitter>
<Nbotz> I want to make it so that when another hash is added into the array, the output changes without having to recompile
<FromGitter>
<Nbotz> its for file uploading
<oprypin>
but like.. changing a crystal file and not having to recompile are conflicting goals!
<lvmbdv>
yeah a dynamic language might be a better fit for the job
<oprypin>
better fit for this backwards solution maybe
<lvmbdv>
oh yeah it sounds really weird
<oprypin>
Nbotz: keep this information in a json file and load it from the crystal program
<FromGitter>
<Nbotz> ok thanks
DTZUZO has joined #crystal-lang
spacemanspam has joined #crystal-lang
simerax has quit [Remote host closed the connection]
<FromGitter>
<j8r> Is it append only @Nbotz ?
<FromGitter>
<j8r> If yes, an effiecient way is to store the infos in a csv file, and watch the file for new lines
<FromGitter>
<Nbotz> yes, append only.
<FromGitter>
<j8r> What are you doing exactly with file uploading?
<FromGitter>
<Nbotz> uploading the pictures and information. the pictures go into the folder while the information would go into the file
<FromGitter>
<j8r> Oh ok i see, a sort of index
<FromGitter>
<Nbotz> yes
Raimondi has joined #crystal-lang
<FromGitter>
<j8r> But if the file is deleted?
<FromGitter>
<Nbotz> files are deleted manually, meaning i'd just recompile and fix the error manually
<FromGitter>
<j8r> Don't know if it's useful for your usecase, there is a library to watch a folder and files inside it