mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Improve the doc example of method_missing
Improvements are: * Use `symbol` instead of `methId`, described in doc * Add `*args` following method signature * Rescue error in `roman_to_int` and calls `super`, recommended in doc * Call invalid `foo` method to Roman object to raise NoMethodError
This commit is contained in:
parent
045152df9e
commit
042be439d9
Notes:
git
2019-08-31 04:40:14 +09:00
1 changed files with 9 additions and 3 deletions
12
vm_eval.c
12
vm_eval.c
|
@ -634,9 +634,14 @@ NORETURN(static void raise_method_missing(rb_execution_context_t *ec, int argc,
|
|||
* def roman_to_int(str)
|
||||
* # ...
|
||||
* end
|
||||
* def method_missing(methId)
|
||||
* str = methId.id2name
|
||||
* roman_to_int(str)
|
||||
*
|
||||
* def method_missing(symbol, *args)
|
||||
* str = symbol.id2name
|
||||
* begin
|
||||
* roman_to_int(str)
|
||||
* rescue
|
||||
* super(symbol, *args)
|
||||
* end
|
||||
* end
|
||||
* end
|
||||
*
|
||||
|
@ -644,6 +649,7 @@ NORETURN(static void raise_method_missing(rb_execution_context_t *ec, int argc,
|
|||
* r.iv #=> 4
|
||||
* r.xxiii #=> 23
|
||||
* r.mm #=> 2000
|
||||
* r.foo #=> NoMethodError
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
|
Loading…
Add table
Reference in a new issue