More concise (and faster) implementation of Hamster::Tuple

The title says it all.

I suspect that a lot of experienced Ruby programmers don't know this trick. When you subclass a core Ruby class like Array/Hash/String, the Ruby runtime will use the exact same (efficient) data representation "under the hood" for your subclass as it does for the built-in class. Additionally, built-in methods which have a special-cased "fast path" when passed an Array, etc. will generally use the fast path for your subclass as well.
The Tuple *is* the item array. Since Tuple includes Immutable, all new
Tuples are automatically frozen.


On Sat, Jun 21, 2014 at 11:23 PM, Kurtis Rainbolt-Greene <
notifications@github.com> wrote:

> In lib/hamster/tuple.rb:
>
> >      include Immutable
> >
> >      def initialize(*items)
> > -      @items = items.freeze
> > -    end
> > -
> > -    def first
> > -      @items.first
> > -    end
> > -
> > -    def last
> > -      @items.last
> > +      super(items)
>
> Doesn't this mean we no longer freeze the item array?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/hamstergem/hamster/pull/97/files#r14051678>.
>