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.
[ Parent
| on HN ]
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)")