Sha256: f59cf16641a2711f5af02d1f4993262d96d1c00a5c7c4f0a3e156496e04279e9

Contents?: true

Size: 715 Bytes

Versions: 16

Compression:

Stored size: 715 Bytes

Contents

# = OpenHash
#
# OpenHash is akin to an OpenStruct or an OpenObject,
# but it is much simplier in nature. It is a hash with
# an method_missing definition that routes to [] and []=.
#
# == Author
#
# * Trans

# = OpenHash
#
# OpenHash is akin to an OpenStruct or an OpenObject,
# but it is much simplier in nature. It is a hash with
# an method_missing definition that routes to [] and []=.
#
class OpenHash < Hash
  #private *instance_methods.select{|m| m !~ /^__/}

  # New OpenHash.

  def initialize(data)
    super()
    update(data)
  end

  # Route get and set calls.

  def method_missing(s, *a)
    if s =~ /=$/
      self[s] = a[0]
    elsif a.empty?
      self[s]
    else
      super
    end
  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facets-2.8.4 lib/more/facets/openhash.rb
facets-2.8.3 lib/more/facets/openhash.rb
facets-2.8.2 lib/more/facets/openhash.rb
facets-2.8.1 lib/more/facets/openhash.rb
facets-2.8.0 lib/more/facets/openhash.rb
facets-2.7.0 lib/more/facets/openhash.rb
facets-2.6.0 lib/more/facets/openhash.rb
facets-2.4.1 lib/facets/openhash.rb
facets-2.4.4 lib/more/facets/openhash.rb
facets-2.4.2 lib/more/facets/openhash.rb
facets-2.4.3 lib/more/facets/openhash.rb
facets-2.4.5 lib/more/facets/openhash.rb
facets-2.5.0 lib/more/facets/openhash.rb
facets-2.5.1 lib/more/facets/openhash.rb
facets-2.5.2 lib/more/facets/openhash.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/more/facets/openhash.rb