ANN map-1.4.0

A

ara.t.howard

NAME
map.rb

SYNOPSIS
the ruby container you've always wanted: a string/symbol indifferent
ordered
hash that works in all rubies

INSTALL
gem install map

URI
http://github.com/ahoward/map

DESCRIPTION

# maps are ordered. constructing them in an ordered fashion builds
them that
# way
#
m = Map[:k, :v, :key, :val]
m = Map:)k, :v, :key, :val)

m = Map[[:k, :v], [:key, :val]]
m = Map[{:k => :v, :key => :val}]


m = Map.new
m[:a] = 0
m[:b] = 1
m[:c] = 2

p m.keys #=> ['a','b','c'] ### always ordered!
p m.values #=> [0,1,2] ### always ordered!

# maps don't care between symbol and string keys
#
p m[:a] #=> 0
p m["a"] #=> 0

# many functions operate in a way one would expect from an ordered
container
#
m.update:)k2 => :v2)
m.update:)k2, :v2)

# maps keep mapiness for even deep operations
#
m.update :nested => {:hashes => {:are => :converted}}

# maps can give back clever little struct objects
#
m = Map:)foo => {:bar => 42})
s = m.struct
p s.foo.bar #=> 42

USAGE
test/map_test.rb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top