reconstruct my code after reading Metaprogramming Ruby