Bug #2457

Enumerable#grep の例を追加

Added by 5 5 about 2 years ago. Updated 10 months ago.

[ruby-reference-manual:1900]
Status:Closed Start date:12/08/2009
Priority:Low Due date:
Assignee:- % Done:

100%

Category:doc
Target version:-
reporter:5.5 ruby_version:1.8, 1.9

Description

Enumerable#grep の実行例に,
名前の一部からメソッドを探したり,特定のクラスのオブジェクトを探す例を
追加しては如何でしょうか。
実用性もあり,grep や === の理解を促進すると思います。

Index: refm/api/src/_builtin/Enumerable
===================================================================
--- refm/api/src/_builtin/Enumerable	(revision 3863)
+++ refm/api/src/_builtin/Enumerable	(working copy)
@@ -155,7 +155,19 @@

 例:
     p ['aa', 'bb', 'cc', 'dd', 'ee'].grep(/[bc]/)  # => ["bb", "cc"]
+    
+    # アタリをつけてメソッドを探す例:
+#@since 1.9.1
+    [].methods.grep(/gr/) # => [:grep, :group_by]
+#@else
+    [].methods.grep(/gr/) # => ["grep", "group_by"]
+#@end
+    
+    # 特定クラスのオブジェクトを探す例:
+    ObjectSpace.each_object.grep(Thread) # => [#<Thread:0xc22dbc run>]

+@see [[m:Object#===]]
+
 #@since 1.8.0
 --- inject(init = self.first) {|result, item| ... } -> object
 #@since 1.8.7

Associated revisions

Revision 4187
Added by okkez over 1 year ago

add sample code for Enumerable#grep (close #2457)

History

Updated by okkez _ over 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r4187.
5, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF