Foo.new id: 1
alias DeviceName = String alias DeviceFile = Int32 alias DeviceDir = Hash(DeviceName, DeviceFile | DeviceDir) pp Hash(DeviceName, DeviceDir).new pp Hash(DeviceName, DeviceFile).new pp DeviceDir.new #=> 21 | pp DeviceDir.new #=> ^-- #=> Error: undefined method 'new' for DeviceDir.class
DeviceDiris an alias of
Hash(DeviceName, DeviceFile | DeviceDir), why can't I call
Optionsarray can hold, but
addmethod isn't imposing any restriction, so it might break for cases where you call
addwith type which isn't part of your expected types.
this snippet contains a macro check for
add method and ensure only allowed types are allowed at compile time. So if you try invoking
add method with Types which aren't part of
Type alias, it will fail to compile.
also in your class you have restricted the types which Options array can hold, but add method isn't imposing any restriction, so it might break for cases where you call add with type which isn't part of your expected types.
Good call, I'd actually be fine without such restriction; just an array of OptionBuilder(T). I'd like to use the type to cast string values to (T), but probably not the best idea: https://play.crystal-lang.org/#/r/e7uu