[前][次][番号順一覧][スレッド一覧]

ruby-changes:59380

From: zverok <ko1@a...>
Date: Mon, 23 Dec 2019 02:23:16 +0900 (JST)
Subject: [ruby-changes:59380] 5fa9c2eeb0 (master): Actualize Method#inspect docs

https://git.ruby-lang.org/ruby.git/commit/?id=5fa9c2eeb0

From 5fa9c2eeb04a2e44a2a028d933bc95f219a6a282 Mon Sep 17 00:00:00 2001
From: zverok <zverok.offline@g...>
Date: Sat, 21 Dec 2019 22:31:30 +0200
Subject: Actualize Method#inspect docs


diff --git a/proc.c b/proc.c
index 2e5654a..73d9464 100644
--- a/proc.c
+++ b/proc.c
@@ -2766,11 +2766,30 @@ rb_method_parameters(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2766
  *
  *  Returns a human-readable description of the underlying method.
  *
- *    "cat".method(:count).inspect   #=> "#<Method: String#count>"
- *    (1..3).method(:map).inspect    #=> "#<Method: Range(Enumerable)#map>"
+ *    "cat".method(:count).inspect   #=> "#<Method: String#count(*)>"
+ *    (1..3).method(:map).inspect    #=> "#<Method: Range(Enumerable)#map()>"
  *
  *  In the latter case, the method description includes the "owner" of the
  *  original method (+Enumerable+ module, which is included into +Range+).
+ *
+ *  +inspect+ also provides, when possible, method argument names (call
+ *  sequence) and source location.
+ *
+ *    require 'net/http'
+ *    Net::HTTP.method(:get).inspect
+ *    #=> "#<Method: Net::HTTP.get(uri_or_host, path=..., port=...) <skip>/lib/ruby/2.7.0/net/http.rb:457>"
+ *
+ *  <code>...</code> in argument definition means argument is optional (has
+ *  some default value).
+ *
+ *  For methods defined in C (language core and extensions), location and
+ *  argument names can't be extracted, and only generic information is provided
+ *  in form of <code>*</code> (any number of arguments) or <code>_</code> (some
+ *  positional argument).
+ *
+ *    "cat".method(:count).inspect   #=> "#<Method: String#count(*)>"
+ *    "cat".method(:+).inspect       #=> "#<Method: String#+(_)>""
+
  */
 
 static VALUE
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]