Gist 54292
✓ Published0🌍 Public
DDylanFM
Last edited Jan 29, 2009
Created on Jan 29, 2009
This example demonstrates how Ruby’s `instance_variable_set` and `instance_variable_get` can dynamically alter and read an instance variable defined on a class, using a module-scoped `@foo` that starts as `"bar"` and is changed to `"changed"` via a nested class method. The code defines a `What` module containing `@foo` and a `Whatever` class whose `change_foo` method mutates that variable, then prints its initial and updated values using `p`. The output, shown as comments (`# >> "bar"` and `# >> "changed"`), confirms the state change. No external libraries or rendering APIs are used; the example relies solely on Ruby’s core object model and metaprogramming features.
AI-generated description