Class: Hash
Overview
Instance Method Summary collapse
-
#each_except(e, &b) ⇒ Object
x = { :none => String, :png => “file.png”, :svg => “file.svg” }.
-
#key(v) ⇒ Object
Add Hash#key to Ruby < 1.9.
- #symbolize_keys ⇒ Object
Instance Method Details
#each_except(e, &b) ⇒ Object
x =
:none => String,
:png => "file.png",
:svg => "file.svg"
x.each_except( :key => [:none], :value => [/.png$/] ) do |k, v|
puts "#{k} -> #{v}"
end
> svg -> file.svg
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/graphviz/core_ext.rb', line 46 def each_except( e, &b ) key_table = (e[:key]||[]).clone.delete_if {|i| i.kind_of? Regexp } key_regexp = (e[:key]||[]).clone.delete_if {|i| key_table.include? i }.map {|i| i.to_s }.join("|") value_table = (e[:value]||[]).clone.delete_if {|i| i.kind_of? Regexp } value_regexp = (e[:value]||[]).clone.delete_if {|i| value_table.include? i }.map {|i| i.to_s }.join("|") self.each do |k, v| yield( k, v ) unless (key_table.size > 0 and key_table.include?(k)) or (key_regexp.size > 0 and k.to_s.match(key_regexp)) or (value_table.size > 0 and value_table.include?(v)) or (value_regexp.size > 0 and v.to_s.match(value_regexp)) end end |
#key(v) ⇒ Object
Add Hash#key to Ruby < 1.9
60 61 62 |
# File 'lib/graphviz/core_ext.rb', line 60 def key(v) index(v) end |
#symbolize_keys ⇒ Object
28 29 30 31 32 33 |
# File 'lib/graphviz/core_ext.rb', line 28 def symbolize_keys inject({}) do |, (key, value)| [(key.to_sym rescue key) || key] = value end end |