3 ms·
Careful with one of those tips [* x] does return x if x is an array and [x] otherwise except in the case where x is a hash in which case it transforms the hash
by gommm 17y ago
Careful with one of those tips [* x] does return x if x is an array and [x] otherwise except in the case where x is a hash in which case it transforms the hash to an array. Eg:
x = {:a => 1, :b => 2}
[* x]
=> [[:a, 1], [:b, 2]]
Some of the other tips just make the code less readable
- pvg 17y agoAlthough he does helpfully preface several with 'this is a bad example' and 'this is not really a good idea'. I like how #1 is about 'taking the pain out of the process' where the 'pain' to be removed appears to be 'the method name that describes what your code is doing'. I also learned that "Array#*, when supplied with a number, multiplies the size of the array by duplicate elements". I can only assume this is a very common and useful operation out there in GPU Vector Magic Land. I was somewhat disappointed that #12 suggested using ranges for number comparison instead of the obviously more idiomatic solution of manipulating metaclasses so every number has a working 'decade' method.