S
Sam Roberts
I just noticed I can't do:
x = Struct.new(...
puts x[3, 4]
I'm doing this, instead, which works fine:
x = Struct.new(...
puts x.to_a[3, 4]
I guess it is because [] is not part of Enumerable, but why isn't []
defined by Enumerable? Is it because random access is so inefficient
when implemented with an iterator, for large collections, anyhow?
Maybe I answered my own question.
I vaguely remember some discussion of some modules that would allow a
class that supported to_str mix in support for all the other String
methods, and something similar for Array/to_a, as well.
I'd like to mix a little bit more of Array into Struct!
Cheers,
Sam
x = Struct.new(...
puts x[3, 4]
I'm doing this, instead, which works fine:
x = Struct.new(...
puts x.to_a[3, 4]
I guess it is because [] is not part of Enumerable, but why isn't []
defined by Enumerable? Is it because random access is so inefficient
when implemented with an iterator, for large collections, anyhow?
Maybe I answered my own question.
I vaguely remember some discussion of some modules that would allow a
class that supported to_str mix in support for all the other String
methods, and something similar for Array/to_a, as well.
I'd like to mix a little bit more of Array into Struct!
Cheers,
Sam