Thank you, nobu! That explains it. Just to clarify, is this how the expression is parsed? ```ruby ( [1, 2] in a, b ) if b == 2*a ``` And since this is a modifier `if`, the parser creates variables a and b first, which is why t...Soilent (Konstantin x)
The following expression produces a TypeError, which is quite unexpected: ```ruby [1, 2] in a, b if b == 2*a ``` ``` x.rb:1:in `*': nil can't be coerced into Integer (TypeError) [1, 2] in a, b if b == 2*a ...Soilent (Konstantin x)
Eregon (Benoit Daloze) wrote: > Soilent (Konstantin x) wrote: > ... I see your point, but the example was not about String to Time caching. Let's say you receive an HTTP POST request with the body `timestamp=2018-03-08T11:24:44Z&temper...Soilent (Konstantin x)
mame (Yusuke Endoh) wrote: > I think it is not so simple to optimize the double lookup by this API. Consider: > ... I think that an exception should be thrown if the block modifies the hash.Soilent (Konstantin x)
sawa (Tsuyoshi Sawada) wrote: > Why not write `hash[:a]+= 42`? Good point, but this works only for arithmetic operators (and also does 2 key lookups). Consider another example `hash.store(:time) { |ts| Time.parse(ts) }`Soilent (Konstantin x)
Hanmac (Hans Mackowiak) wrote: > ~~~ ruby > ... Thanks for the question. I think that `hash.store(:b)` should yield the default value if the key does not exist, i.e. option b. But in case of `hash.transform_values(:a, :b)`, when we...Soilent (Konstantin x)
Eregon (Benoit Daloze) wrote: > What should happen if the given key doesn't exist in Hash? > ... Good question, thank you. I think, the result of default_proc or the default value should be yielded.Soilent (Konstantin x)