I can\'t seem to find a definitive answer on this and I want to make sure I understand this to the \"n\'th level\" :-)
a = { \"a\" => \"Hello\", \"b\" => \"Worl
In most cases (e.g. Array or String) size
is an alias for length
.
count
normally comes from Enumerable and can take an optional predicate block. Thus enumerable.count {cond}
is [roughly] (enumerable.select {cond}).length
-- it can of course bypass the intermediate structure as it just needs the count of matching predicates.
Note: I am not sure if count
forces an evaluation of the enumeration if the block is not specified or if it short-circuits to the length
if possible.
Edit (and thanks to Mark's answer!): count
without a block (at least for Arrays) does not force an evaluation. I suppose without formal behavior it's "open" for other implementations, if forcing an evaluation without a predicate ever even really makes sense anyway.