Those items seem useful, because Hashes are not as set-theoretic as
Arrays. I
suspect, for example, one cannot & two Hashes to extract their
intersection.
That post is from 2006 - essentially the Neolithic Era!
Now what should the last line yield? Both { :one => 1, :two => 2 } and
{ [:one, :two] => [1, 2] } would be valid, depending on how you
interpret [:one, :two] (array of keys vs. single key).
Thanks - I guessed as much, but isn’t there also another Boost-style
library for
Ruby? (Boost is essentially Facets for C++ - a repository of reference
implementations for future Standardization, complete with their
implications.)
def slice(*keep_keys)
It’s okay, but…
If I already have an array, I have to splat * it in:
Oops, my fault. I wasn’t aware of the fact that I tested it only with
Ruby 1.8.7 (it works there). With Ruby 1.8.6 it fails miserably.
More importantly, Facets implementation is the way it is b/c it is
fast. Code elegance is nice, but you won’t be looking at the code when
you are using it.
I must admit that execution speed wasn’t one of my priorities for this
snippet. But your point is very valid–I’d also recommend sticking with
the Facets implementation if speed is of any concern.
Dude that’s so lean I’m tossing facets and going with it. Tx!
#pass doesn’t seem to work, at least not in 1.8.
More importantly, Facets implementation is the way it is b/c it is
fast. Code elegance is nice, but you won’t be looking at the code when
you are using it.
Oops, my fault. I wasn’t aware of the fact that I tested it only with
Ruby 1.8.7 (it works there). With Ruby 1.8.6 it fails miserably.
Take off the Hash[].
More importantly, Facets implementation is the way it is b/c it is
fast. Code elegance is nice, but you won’t be looking at the code when
you are using it.
I must admit that execution speed wasn’t one of my priorities for this
snippet. But your point is very valid–I’d also recommend sticking with
the Facets implementation if speed is of any concern.
I needed to slow down my hacking long enough to install facets on our
pairstations, and achieve buy-in, so I will go with this version first.
Also, it’s currently only test-side, so speed is slightly less relevant.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.