Skip to content

Commit

Permalink
Doc. update
Browse files Browse the repository at this point in the history
  • Loading branch information
akzhan committed Sep 10, 2013
1 parent 4a9f1d4 commit 196682c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/reg_api2/sym_hash.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module RegApi2
# Hash with indifferent access to its elements.
# Also have no difference between {String} ans {Symbol} keys.
class SymHash < Hash
# Forms data with indifferent access from specified source.
# @return [Object] Data with indifferent access
def self.from(source)
case source
when Hash
Expand All @@ -17,14 +21,22 @@ def self.from(source)
end
end

# Returns true if the given key is present in hsh.
def has_key?(key)
key.kind_of?(Symbol) ? self.has_key?(key.to_s) : super(key)
end

# Returns true if the given key is present in hsh.
def include?(key)
has_key?(key)
end

# Element Reference — Retrieves the value object corresponding to the key object. If not found, returns the default value (see {Hash::new} for details).
def [](key)
key.kind_of?(Symbol) ? self[key.to_s] : super(key)
end

# Element Assignment — Associates the value given by value with the key given by key. key should not have its value changed while it is in use as a key (a String passed as a key will be duplicated and frozen).
def []=(key, new_value)
key.kind_of?(Symbol) ? self[key.to_s]=new_value : super(key, new_value)
end
Expand Down

0 comments on commit 196682c

Please sign in to comment.