diff options
author | Michael Herold <michael.j.herold@gmail.com> | 2015-04-18 20:13:06 -0500 |
---|---|---|
committer | Michael Herold <michael.j.herold@gmail.com> | 2015-04-18 20:13:06 -0500 |
commit | fc4b183eff6ec51270d7ec11e95536f8cf0e304a (patch) | |
tree | e3e2cc0fa725d54209ea75a6a137eedad2c64b9c | |
parent | 35756e1641b6ab31b16951d0bd42e3abe5eb9e55 (diff) | |
download | hashie-fc4b183eff6ec51270d7ec11e95536f8cf0e304a.tar.gz |
Clarify the in-line documentation for DeepFind
Fixes #284
-rw-r--r-- | lib/hashie/extensions/deep_find.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/hashie/extensions/deep_find.rb b/lib/hashie/extensions/deep_find.rb index d22476a..616e659 100644 --- a/lib/hashie/extensions/deep_find.rb +++ b/lib/hashie/extensions/deep_find.rb @@ -5,7 +5,16 @@ module Hashie # a key and returns the first occurrence of the key. # # options = {user: {location: {address: '123 Street'}}} + # options.extend(Hashie::Extensions::DeepFind) # options.deep_find(:address) # => '123 Street' + # + # class MyHash < Hash + # include Hashie::Extensions::DeepFind + # end + # + # my_hash = MyHash.new + # my_hash[:user] = {location: {address: '123 Street'}} + # my_hash.deep_find(:address) # => '123 Street' def deep_find(key) _deep_find(key) end @@ -16,7 +25,16 @@ module Hashie # a key and returns all occurrences of the key. # # options = {users: [{location: {address: '123 Street'}}, {location: {address: '234 Street'}}]} + # options.extend(Hashie::Extensions::DeepFind) # options.deep_find_all(:address) # => ['123 Street', '234 Street'] + # + # class MyHash < Hash + # include Hashie::Extensions::DeepFind + # end + # + # my_hash = MyHash.new + # my_hash[:users] = [{location: {address: '123 Street'}}, {location: {address: '234 Street'}}] + # my_hash.deep_find_all(:address) # => ['123 Street', '234 Street'] def deep_find_all(key) matches = _deep_find_all(key) matches.empty? ? nil : matches |