File: 02_query_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 (17 lines) | stat: -rw-r--r-- 402 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
= QueryHash

A QueryHash is a Hash that provides open access much like an OpenHash, but it limits readers
to bang and query methods (i.e. method ending in `!` or `?`).

  q = QueryHash.new
  q.a = 1
  q.b = 2
  q.a?.assert == 1
  q.b?.assert == 2

By default keys are converted to strings.

  q.assert == { "a"=>1, "b"=>2 }

A QueryHash is compatible with Ruby's standard Hash in every other respect.