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> <leelavg> hi, quick check, what should take the precedence (type in init or type on instance var) while creating an object? ⏎ ⏎ ```class H(T) ⏎ property name : String ⏎ def initialize(@name : T) ⏎ end ⏎ end``` ⏎ ⏎ ps: I'm still learning the language, thanks in advance [https://gitter.im/crystal-lang/crystal?at=62f33d41443b7927a73b2375]
<Sankalp> Hi leelavg, I didn't quite get your question
<Sankalp> Actually, got it
<Sankalp> @leelavg, is there a reason you are going with String as a type rather than the generic type (T) in `property name : String`?
_ht has joined #crystal-lang
notzmv has quit [Ping timeout: 268 seconds]
<FromGitter> <leelavg> well, I was just checking which takes precedence. like when'll type restriction is put in place, whether from the init or from property.
<Sankalp> `H(String).new("")` works but `H(Int).new(1)` gives a compilation error.
<Sankalp> and that's because `T` is only able to take `String` due to the type restriction set on `name`
<Sankalp> So even if the code was like
<Sankalp> ```
<Sankalp> ```
<Sankalp> property name : T
<Sankalp> class H(T)
<Sankalp> def initialize(@name : String)
<Sankalp> end
<Sankalp> end
<Sankalp> ```
<Sankalp> you'd still get the same result
notzmv has joined #crystal-lang
amk_ has joined #crystal-lang
amk_ has quit [Changing host]
amk_ is now known as amk
jmdaemon has quit [Ping timeout: 268 seconds]
<FromGitter> <leelavg> ack, specific type wins over generic type. Even though it's an absurd question thanks for the explanation :)
<Sankalp> cheers :)
Stephie has quit [Quit: Fuck this shit, I'm out!]
llua has left #crystal-lang [WeeChat 3.5]
Stephie has joined #crystal-lang
notzmv has quit [Ping timeout: 268 seconds]
notzmv has joined #crystal-lang
notzmv has quit [Ping timeout: 268 seconds]
jmiven has quit [Quit: reboot]
jmiven has joined #crystal-lang
renich has joined #crystal-lang
<FromGitter> <Blacksmoke16> might also be worth pointing out its failing on the assign to the ivar if the generic is not `String`, which is due to the fact that `@name : T` expands to like `@name = name` where `def initialize(name : T)`
<FromGitter> <Blacksmoke16> e.g. you could do like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=62f3f4df72ad51741f0a96fc]
<FromGitter> <Blacksmoke16> i.e. the generic *does* allow the value to make it thru the initialize method ,but fails in the assign. whereas in other cases it would fail due to not finding a valid overload because of the generic restriction on the constructor param
Sankalp has quit [Ping timeout: 252 seconds]
Sankalp has joined #crystal-lang
notzmv has joined #crystal-lang
jmdaemon has joined #crystal-lang
<SamantazFox> Hello! I'm not sure what the `same_thread` parameter means in `spawn()`.Could someone explain please?
<FromGitter> <Blacksmoke16> only applicable if you're running with MT mode afaik
<SamantazFox> Ah, Ok!
_ht has quit [Quit: _ht]
tomhg has quit [Quit: leaving]
oz` is now known as oz
irc_user has joined #crystal-lang