New answers tagged

0

It's a bit unusual, but why not? Let's say I need to lookup objects based on two integer values, then it would be totally obvious to have a hash that uses an array with two integers as the key.


1

[How what you tried works first, why such keys are useful at the end.] Behavior depends on the key, specifically what its .hash and .eql? methods do. The 2 common strategies (appearing in many languages) are hashing by value and by identity. [Well, there is a third one: not allowing certain types as keys.] An extremely familiar example is strings hashing ...


1

The right answer involves a lot of, "Not quite," with a sprinkling of, "You have a point." First let's take a literal interpretation. Ruby has class methods and instance methods. Class methods are the methods of the class object. Instance methods are the methods of instances of that class. Inheritance is a relationship between class objects - calling ...


0

In this case I suspect that the Liskov principle would imply that now each subclass must also support .new without any arguments That's not correct. You require here that the metaobject of some class derived from BaseObject need to support niladic new, because the metaobject of BaseObject does. The LSP states that objects of a subclass must support ...


2

In this case I suspect that the Liskov principle would imply that now each subclass must also support .new without any arguments Your suspicion is wrong. The problem is that you're inferring from the base class's implementation what the base class's contract is. But they are two distinct things, even if not literally written out separately. In this ...


3

Languages vary greatly in how classes are manifest (i.e. at runtime). In some language systems, there is no runtime manifestation of a class, so Liskov is simply not applicable to classes. the runtime manifestation of all class is a direct instance (of some class like TYPE or CLASS, for example), and all they are is a token that represents a specific real ...



Top 50 recent answers are included