Guest User

Untitled

a guest
Jun 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.20 KB | None | 0 0
  1. class C
  2. def addVar name, val
  3. class <<self
  4. self
  5. end.class_eval do
  6. attr_reader :"#{name}"
  7. end
  8. instance_variable_set :"@#{name}", val
  9. end
  10. end
  11.  
  12. c = C.new
  13. c.addVar "foo", 42
  14. p c.foo
Add Comment
Please, Sign In to add comment