4 ms·
This isn't that crazy IMO, both Kotlin and Scala 3 allow this with extension methods https://kotlinlang.org/docs/extensions.html https://kotlinlang.org/docs/ex
by gavinray 5y ago
This isn't that crazy IMO, both Kotlin and Scala 3 allow this with extension methods
https://kotlinlang.org/docs/extensions.html https://kotlinlang.org/docs/extensions.html
https://docs.scala-lang.org/scala3/book/ca-extension-methods.html https://docs.scala-lang.org/scala3/book/ca-extension-methods...
- Tainnor 5y agoAt least Kotlin (probably Scala too) requires you to explicitly import the corresponding method though. In Ruby, however, there is no concept of an import. You can require other files but this is transitive. So if something anywhere in your chain of dependencies is defining a new method on String, or Object, it's available everywhere. Plus, in Rails usually you don't even have to require anything, as the framework magic does that for you. The fact that there is no proper import/module system is easily one of my most disliked features about Ruby, it makes it incredibly hard to understand where things come from. Also, Ruby doesn't only allow you to add new behaviour to existing classes. It also allows overriding existing methods. And that suffers from the exact same problems, i.e. it could be in some transitive dependency, and suddenly your strings will be doing things you didn't expect them to do...