File: 03_casting_hash.rdoc

package info (click to toggle)
ruby-hashery 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 404 kB
  • sloc: ruby: 2,997; makefile: 7
file content (12 lines) | stat: -rw-r--r-- 260 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
= CastingHash

A CastingHash is a Hash that allows _casting_ procedures to
defined that the keys and values pass through upon assignment.

  c = CastingHash.new
  c.cast_proc = lambda { |k,v| [k.to_s, v.to_s.upcase] }

  c[:a] = 'a'

  c.assert == {'a'=>'A'}