3 ms·
Comparisons to python are difficult here because in Ruby there's no such thing as an object that doesn't have a class. Even the classes have classes (which is,
by stormbrew 13y ago
Comparisons to python are difficult here because in Ruby there's no such thing as an object that doesn't have a class. Even the classes have classes (which is, as I touched on elsewhere, what class methods actually are -- instance methods on the class).
You can store a proc in a variable or a constant, but you're getting into some very ugly patterns at that point and you still haven't really left classes behind.
In Ruby everything is encapsulated and there's really no point in fighting that.
- lmm 13y ago> Comparisons to python are difficult here because in Ruby there's no such thing as an object that doesn't have a class. Even the classes have classes (which is, as I touched on elsewhere, what class methods actually are -- instance methods on the class So exactly the same as Python then? > You can store a proc in a variable or a constant, but you're getting into some very ugly patterns at that point and you still haven't really left classes behind. How so? If you need to pass around something that quacks like a proc, do it as a proc.
- stormbrew 13y ago> So exactly the same as Python then? Recently? Sort of, yes. Though in python it's more like everything has a blessed hash, and the assumption that everything is an object is much more thoroughly baked in in Ruby. Also the way that classes interact with their instances is quite different. For example, in python a member of the class that is not overridden in an instance also happens to be a member of an instance. This is how default attributes work: >>> class x(object): ... pass ... >>> x.blah = 1 >>> x().blah 1 This actually gives you something qualitatively like a static method (through the staticmethod decorator), it is callable from an instance as well as the class and behaves always as if it has no access to the instance's state. This kind of blending of instance and class doesn't happen in Ruby. The class is a completely distinct object with its own independent state, and is instantiated just like any other object, some syntactic sugar aside. It is an instance of class Class and its methods are the methods of class Class, while instances created by calling its #alloc method have the methods that are defined on it. Python now shares some concept of everything being an object, I'll grant, but their models remain quite different and you really do have to work significantly against the grain to effectively use ruby in a non-OO fashion. In ways you simply don't in Python.