Issue #14967 has been updated by shevegen (Robert A. Heiler).


"[...] If we choose to pursue pattern matching [Feature #14912]
further, I believe a wildcard type would be exceptionally
useful. [...]"

I believe matz already gave approval to the suggestion/idea
itself behind pattern matching for feature #14912, as can 
be seen by the log made during the ~last developer meeting:

https://docs.google.com/document/d/1_cKh0LJd18y5CH1MfM6WC1fqh2rpHHZntrBCLTbwRSE/edit

But he also said that there are many details missing as of yet.

I suppose this may be further discussed, perhaps even at another
developer meeting in the future.

----------------------------------------
Feature #14967: Any type
https://bugs.ruby-lang.org/issues/14967#change-73356

* Author: baweaver (Brandon Weaver)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Scala, there's the concept of an Any type which can be used to match anything.

The implementation of which is quite simple: https://github.com/baweaver/any

```ruby
class Any
  class << self
    def ===(b)
      true
    end

    def ==(b)
      true
    end

    def to_proc
      proc { true }
    end
  end
end
```

What this allows us though is the ability to really maximize the potentials of both `Hash#===` [Feature #14869] and `Array#===` [Feature #14916]:

```ruby
case ['Foo', 25]
when [/^F/, Any] then true
else false
end
# => true

case {id: 1, name: 'foo', age: 42}
when {id: Any, name: /^f/, age: Any} then true
else false
end
# => true

case {id: 1, name: 'foo'}
when {id: Any, name: /^f/, age: Any} then true
else false
end
# => false
```

This could potentially be an alias for Object as well, as the current idea would only work with `===`. `is_a?` would return false.

If we choose to pursue pattern matching [Feature #14912] further, I believe a wildcard type would be exceptionally useful.



-- 
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>