Sha256: f851c73be57f039655a2bb583639c132ddbc4f86ecb6646588d9089d5ee13fcc
Contents?: true
Size: 1.29 KB
Versions: 12
Compression:
Stored size: 1.29 KB
Contents
class String def self.random(size) s = "" d = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a size.times { s << d[rand(d.size)] } return s end end # From : http://www.geekmade.co.uk/2008/09/ruby-tip-normalizing-hash-keys-as-symbols/ class Hash def symbolize_keys inject({}) do |options, (key, value)| options[(key.to_sym rescue key) || key] = value options end end # 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 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 end
Version data entries
12 entries across 12 versions & 1 rubygems