From: keystonelemur@... Date: 2018-08-06T03:09:34+00:00 Subject: [ruby-core:88303] [Ruby trunk Feature#14967] Any type Issue #14967 has been reported by baweaver (Brandon Weaver). ---------------------------------------- Feature #14967: Any type https://bugs.ruby-lang.org/issues/14967 * 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: