summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-05-10 19:43:40 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-05-10 19:43:40 +0900
commit98e035ae0939822152fac369083280be8acdf85e (patch)
tree940ea979784ba40975792bffd3b4fc66d9c0d5a6
parentadea2ca371e6d986eb794d996c0f6165a2881b9b (diff)
parent012c32ad0a196e133a1a6752a0d3e980ef225387 (diff)
downloadmruby-98e035ae0939822152fac369083280be8acdf85e.tar.gz
mruby-98e035ae0939822152fac369083280be8acdf85e.zip
Merge pull request #2228 from suzukaze/add-comments-to-hash
Add comments to Hash methods
-rw-r--r--mrblib/hash.rb54
1 files changed, 50 insertions, 4 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index 315a0c86e..9bb146b27 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -205,7 +205,16 @@ class Hash
# ISO 15.2.13.4.31 (x)
alias to_s inspect
- # 1.8/1.9 Hash#reject! returns Hash; ISO says nothing.
+ ##
+ # call-seq:
+ # hsh.reject! {| key, value | block } -> hsh or nil
+ # hsh.reject! -> an_enumerator
+ #
+ # Equivalent to <code>Hash#delete_if</code>, but returns
+ # <code>nil</code> if no changes were made.
+ #
+ # 1.8/1.9 Hash#reject! returns Hash; ISO says nothing.
+ #
def reject!(&b)
return to_enum :reject! unless block_given?
@@ -222,7 +231,21 @@ class Hash
self
end
- # 1.8/1.9 Hash#reject returns Hash; ISO says nothing.
+ ##
+ # call-seq:
+ # hsh.reject {|key, value| block} -> a_hash
+ # hsh.reject -> an_enumerator
+ #
+ # Returns a new hash consisting of entries for which the block returns false.
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
+ # h.reject {|k,v| k < "b"} #=> {"b" => 200, "c" => 300}
+ # h.reject {|k,v| v > 100} #=> {"a" => 100}
+ #
+ # 1.8/1.9 Hash#reject returns Hash; ISO says nothing.
+ #
def reject(&b)
return to_enum :reject unless block_given?
@@ -235,7 +258,16 @@ class Hash
h
end
- # 1.9 Hash#select! returns Hash; ISO says nothing.
+ ##
+ # call-seq:
+ # hsh.select! {| key, value | block } -> hsh or nil
+ # hsh.select! -> an_enumerator
+ #
+ # Equivalent to <code>Hash#keep_if</code>, but returns
+ # <code>nil</code> if no changes were made.
+ #
+ # 1.9 Hash#select! returns Hash; ISO says nothing.
+ #
def select!(&b)
return to_enum :select! unless block_given?
@@ -252,7 +284,21 @@ class Hash
self
end
- # 1.9 Hash#select returns Hash; ISO says nothing.
+ ##
+ # call-seq:
+ # hsh.select {|key, value| block} -> a_hash
+ # hsh.select -> an_enumerator
+ #
+ # Returns a new hash consisting of entries for which the block returns true.
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
+ # h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300}
+ # h.select {|k,v| v < 200} #=> {"a" => 100}
+ #
+ # 1.9 Hash#select returns Hash; ISO says nothing
+ #
def select(&b)
return to_enum :select unless block_given?