A singleton object is more than a holder of static methods, however. It is a first-class object. You can think of a singleton object’s name, therefore, as a “name tag” attached to the object.
I fail to see how it can be the case, one cannot assign a singleton to value, nor send it to a method. Or is it actually possible?
in Scala 3 one can define an extension method on a singleton type:
extension (s: "Jennifer")
def mySize = s.size
and in Scala 2:
implicit class MySize(s: "Jennifer") {
def mySize = s.size
}
But it’s not really the same as your Ruby example, because the Scala versions are resolved at compile-time, whereas the Ruby one is resolved at runtime (right? I don’t really know Ruby). So one can:
scala 2.13.8> "Jennifer".mySize
val res6: Int = 8
scala 2.13.8> val word: "Jennifer" = "Jennifer"
val word: "Jennifer" = Jennifer
scala 2.13.8> "Jennifer".mySize
val res7: Int = 8
But one cannot:
scala 2.13.8> val word = "Jennifer"
val word: String = Jennifer
scala 2.13.8> word.mySize
^
error: value mySize is not a member of String
Here word is only known to have type String at compile-time, so the extension method isn’t found.
Seth you are right. I think for types stuff the script language would be checking at run time. This is the reason why Spark has Dataset structures for Java/Scala but not for Python/R.