HashPipe – hash-alike openstructs for ruby.

Come on and kick me.
You’ve got your problems;
I’ve got my ass wide
You’ve got your big G's;
I’ve got my hash pipe.

- Weezer, /Hash Pipe/

HashPipe is a library to supplement users of OpenStruct and similar libs. It operates leak free at insertion cost and optimizes for the common case: reading, like a good hash table should. HashPipe includes Enumerable and a basic keys/values implementation.

HashPipe also contains a locking mechanism whereby you can eliminate the ability to add more items, similar to Object#freeze in a sense.

Examples:

h = HashPipe.new
h[:foo] = "bar"
h.foo             #=> "bar"
h["bar"] = "quux"
h[:bar]           #=> "quux"
h.bar             #=> "quux"

h.lock!   # no new attributes can be created

h.quux    # raises
h[:quux]  # raises
h['quux'] # raises
h.foo     #=> "bar"

h.keys    #=> [:foo, :bar]
h.values  #=> ["bar", "quux"]

h.map { |k,v| [k,v] } #=> [[:foo, "bar"], [:bar, "quux"]]

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Erik Hollensbe. See LICENSE for details.