add_a_variable_to_a_class_instance_at_runtime.sf 170 B

1234567
  1. #!/usr/bin/ruby
  2. class Empty{};
  3. var e = Empty(); # create a new class instance
  4. e{:foo} = 42; # add variable 'foo'
  5. say e{:foo}; # print the value of 'foo'