Sha256: f58177b44546497ee801065db93066ffe02de16275dc261f6b65681f30370152

Contents?: true

Size: 654 Bytes

Versions: 2

Compression:

Stored size: 654 Bytes

Contents

# $Id: utils.rb 67 2007-12-09 00:49:26Z tim_pease $

module Enumerable
  def injecting( initial )
    inject(initial) do |memo, obj|
      yield(memo, obj); memo
    end
  end
end

class Hash
  def sanitize!
    h = self.injecting({}) do |h, (k, v)|
          h[k] = case v
                 when 'none', 'nil'; nil
                 when 'true', 'yes'; true
                 when 'false', 'no'; false
                 else v end
        end
    self.replace h
  end

  def stringify_keys
    h = {}
    self.each {|k,v| h[k.to_s] = v}
    return h
  end

  def symbolize_keys
    h = {}
    self.each {|k,v| h[k.to_sym] = v}
    return h
  end
end

# EOF

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webby-0.7.1 lib/webby/utils.rb
webby-0.7.0 lib/webby/utils.rb