Issue #13913 has been updated by matz (Yukihiro Matsumoto).


Evan Phoenix and others (including me) once discussed structural interface check instead of nominal check done by `isa?`. It hasn't become concrete but the idea is similar to your proposal. The discussed API was like:

~~~
arg.conform(InterfaceModule)
~~~

that checks `arg` to have methods described in `InterfaceModule`.

At the moment, I am more tempted by type inference. But you may want to discuss the issue further.

Matz.

----------------------------------------
Bug #13913: Method definition with explicitly callable method names
https://bugs.ruby-lang.org/issues/13913#change-66734

* Author: tagomoris (Satoshi TAGOMORI)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
There are many cases to expect that arguments should respond to a/some methods like this:

```ruby
def call_foo(arg)
  if !(arg.respond_to(:to_s) and arg.respond_to(:to_a) and arg.respond_to(:readpartial))
    raise ArgumentError, "interface mismatch"
  end
end
```

This is very frequent pattern, and I'm very happy to write this code in very short lines like this:

```ruby
def call_foo(arg|to_s,to_a,readpartial)
  # ...
end
```

This feature looks very useful and have space to analyze statically and to optimize dynamically.
And, there may be possibility to allow to have method overriding.

What do you think about this idea?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>