Issue #14967 has been updated by jwmittag (J=F6rg W Mittag). baweaver (Brandon Weaver) wrote: > In Scala, there's the concept of an Any type which can be used to match a= nything. This is a very odd characterization of `scala.Any`. In Scala, `Any` is the = *top type* (in the type-theoretical sense), i.e. the super type of all type= s. In Ruby, we already have the superclass of all classes, namely `::Object= ` or `::BasicObject`, depending on how you look at it. (The Ruby Specificat= ion says that `Object` is the top class but that implementations are allowe= d to add implementation-specific superclasses above it.) Now, Ruby doesn't have types in the same sense that Scala has, so a direct = comparison of a top type with a top class is strenuous at best, but I belie= ve comparing this feature to a top type a la Scala's `scala.Any` is mightil= y confusing. At least, it confused me when I was reading this feature reque= st. If what you want is a pattern wildcard, it would make more sense to explici= tly call it a pattern wildcard rather than confusing it with a top type. ---------------------------------------- Feature #14967: Any type https://bugs.ruby-lang.org/issues/14967#change-80613 * 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 any= thing. The implementation of which is quite simple: https://github.com/baweaver/any ```ruby class Any class << self def =3D=3D=3D(b) true end def =3D=3D(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#=3D=3D=3D` [Feature #14869] and `Array#=3D=3D=3D` [Feature #= 14916]: ```ruby case ['Foo', 25] when [/^F/, Any] then true else false end # =3D> true case {id: 1, name: 'foo', age: 42} when {id: Any, name: /^f/, age: Any} then true else false end # =3D> true case {id: 1, name: 'foo'} when {id: Any, name: /^f/, age: Any} then true else false end # =3D> false ``` This could potentially be an alias for Object as well, as the current idea = would only work with `=3D=3D=3D`. `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=3Dunsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>