News for hackers. Stuff that matters.
Re:How to Dynamically Create Instance Variables in Ruby by revskill on Friday July 28, 2023 @03:49AM (#36904084)
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.

Re:How to Dynamically Create Instance Variables in Ruby by rcxdude on Friday July 28, 2023 @07:25AM (#36905352)
This kind of thing is possible in both python and javascript, it's just generally discouraged.
Re:How to Dynamically Create Instance Variables in Ruby by taf2 on Friday July 28, 2023 @07:40AM (#36905453)
It’s actually easier in JavaScript compared to either language….

var foo = {}

foo.bar = “hello new property”

console.log(foo.bar)

Re:How to Dynamically Create Instance Variables in Ruby by rubyn00bie on Friday July 28, 2023 @08:14AM (#36905737)
Your 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.
Re:How to Dynamically Create Instance Variables in Ruby by danielheath on Friday July 28, 2023 @09:36AM (#36906566)
On the other hand...

foo = {bar: "123"}; with (foo) eval("console.log(bar)")