3 ms·
This is beautiful, but "ugly" at the same time. For example, it allows you to monkey patch at runtime any library that you install. Compare with Javascript, i
by revskill 3y ago
This is beautiful, but "ugly" at the same time.
For example, it allows you to monkey patch at runtime any library that you install.
Compare with Javascript, i'm not sure if you can just install a package, patch it at runtime (like this article is about) to match your need.
In some sense, this is similar to OOP inheritance and overloading, but for intance variables.
That's why most of Ruby startups tends to go faster than other languages, because all Ruby classes is hackable at runtime.
- rcxdude 3y agoThis kind of thing is possible in both python and javascript, it's just generally discouraged.
- taf2 3y agoIt’s actually easier in JavaScript compared to either language…. var foo = {} foo.bar = “hello new property” console.log(foo.bar)
- rubyn00bie 3y agoYour example is not equivalent to the Ruby code. You’re just assigning a value to a property which is always exposed, you’re showing getters/setters. The instance variables are not by default exposed or accessible outside the class/object.
- danielheath 3y agoOn the other hand... foo = {bar: "123"}; with (foo) eval("console.log(bar)")