From: "Vinícius Baggio Fuentes" Date: 2010-05-06T22:06:03+09:00 Subject: Class variable "scope" --0016e6d58f7f47fba20485ec9aff Content-Type: text/plain; charset=ISO-8859-1 Hi all, I've been writing a library for me to play with metaprogramming as an exercise, but then I got stuck on a non-metaprogramming issue: ## a.rb class A def self.add_something(*sth) @@my_things ||= [] @@my_things << sth end def self.my_things @@my_things end end ## b.rb require 'a' class B < A add_something :bag, :boots end require 'a' ## c.rb class C < A add_something :sword, :shield end The result, when requiring both c and b into an irb shell is, as expected: ruby-1.8.7-p249 > C.my_things => [[:bag, :boots], [:sword, :shield]] ruby-1.8.7-p249 > B.my_things => [[:bag, :boots], [:sword, :shield]] I did achieve the following: C.my_things [[:sword, :shield]] B.my_things [[:bag, :boots]] by moving my_things method into each child class and using the method on the add_something method, but there must be a better way. How one could improve this? Thanks in advance! --0016e6d58f7f47fba20485ec9aff--