Class: Hash
- Defined in:
- lib/amp/server/fancy_http_server.rb,
lib/amp/dependencies/maruku/structures_inspect.rb,
lib/amp/support/support.rb
Direct Known Subclasses
Amp::Mercurial::ManifestEntry, PoorPriorityQueue, PythonConfig::ConfigSection, Zip::ZipExtraField
Class Method Summary collapse
-
.with_keys(iterable, value = true) ⇒ Hash
Given a list of key names, and a specified value, we create a hash with those keys all equal to
value.
Instance Method Summary collapse
-
#[](key) ⇒ Hash, Value
Same as #[], but will take regexps and try to match those.
- #get ⇒ Object
- #inspect_ordered(a = nil, b = nil) ⇒ Object
-
#only(*keyz) ⇒ Hash
Construct a new hash with only the specified
keyz. -
#pick(*keys) ⇒ Object
Create a subset of
selfwith keyskeys.
Class Method Details
.with_keys(iterable, value = true) ⇒ Hash
Given a list of key names, and a specified value, we create a hash with those keys all equal to value. Useful for making true/false tables with speedy lookup.
579 580 581 582 583 584 |
# File 'lib/amp/support/support.rb', line 579 def self.with_keys(iterable, value=true) # we try to be functional when it doesn't fuck us over # here, the list of keys will never be ridiculous # so we go fuctional iterable.inject({}) {|h, k| h[k] = value; h } end |
Instance Method Details
#[](key) ⇒ Hash, Value
Same as #[], but will take regexps and try to match those. This will bug out if you are using regexps as keys
13 14 15 16 17 18 19 20 |
# File 'lib/amp/server/fancy_http_server.rb', line 13 def [](key) case key when Regexp select {|k, _| k =~ key }.to_hash else get key end end |
#get ⇒ Object
6 |
# File 'lib/amp/server/fancy_http_server.rb', line 6 alias_method :get, :[] |
#inspect_ordered(a = nil, b = nil) ⇒ Object
48 49 50 51 |
# File 'lib/amp/dependencies/maruku/structures_inspect.rb', line 48 def inspect_ordered(a=nil,b=nil) "{"+keys.map{|x|x.to_s}.sort.map{|x|x.to_sym}. map{|k| k.inspect + "=>"+self[k].inspect}.join(',')+"}" end |
#only(*keyz) ⇒ Hash
Construct a new hash with only the specified keyz
596 597 598 |
# File 'lib/amp/support/support.rb', line 596 def only(*keyz) keyz.inject({}) {|h, k| h[k] = self[k]; h } end |
#pick(*keys) ⇒ Object
Create a subset of self with keys keys.
588 589 590 |
# File 'lib/amp/support/support.rb', line 588 def pick(*keys) keys.inject({}) {|h, (k, v)| h[k] = v; h } end |