Skip to content

Commit 189bb64

Browse files
okuramasafumihsbt
authored andcommitted
[ci-skip] Shorter example for Module#instance_method
The previous example code was too complex and includes extra logics that's not relevant to its main usage: `bind`. The new example code focuses on `bind_call` so that readers can understand how it works more easily.
1 parent 806031d commit 189bb64

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

proc.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,29 +2371,29 @@ rb_obj_singleton_method(VALUE obj, VALUE vid)
23712371
*
23722372
* Returns an +UnboundMethod+ representing the given
23732373
* instance method in _mod_.
2374+
* See +UnboundMethod+ about how to utilize it
23742375
*
2375-
* class Interpreter
2376-
* def do_a() print "there, "; end
2377-
* def do_d() print "Hello "; end
2378-
* def do_e() print "!\n"; end
2379-
* def do_v() print "Dave"; end
2380-
* Dispatcher = {
2381-
* "a" => instance_method(:do_a),
2382-
* "d" => instance_method(:do_d),
2383-
* "e" => instance_method(:do_e),
2384-
* "v" => instance_method(:do_v)
2385-
* }
2386-
* def interpret(string)
2387-
* string.each_char {|b| Dispatcher[b].bind(self).call }
2388-
* end
2389-
* end
2376+
* class Person
2377+
* def initialize(name)
2378+
* @name = name
2379+
* end
2380+
*
2381+
* def hi
2382+
* puts "Hi, I'm #{@name}!"
2383+
* end
2384+
* end
2385+
*
2386+
* dave = Person.new('Dave')
2387+
* thomas = Person.new('Thomas')
23902388
*
2391-
* interpreter = Interpreter.new
2392-
* interpreter.interpret('dave')
2389+
* hi = Person.instance_method(:hi)
2390+
* hi.bind_call(dave)
2391+
* hi.bind_call(thomas)
23932392
*
23942393
* <em>produces:</em>
23952394
*
2396-
* Hello there, Dave!
2395+
* Hi, I'm Dave!
2396+
* Hi, I'm Thomas!
23972397
*/
23982398

23992399
static VALUE

0 commit comments

Comments
 (0)