ruby - Why Am I Getting a SystemStackError In This Code? -


class x   class << self     def attr_string arg       eval("def #{arg}; return #{arg.to_s}; end")     end   end end 

is code working with. trying make class macro, attr_accessor. when call

foo = 50 x.attr_string :foo x.foo 

i systemstackerror. why this?

class x   def attr_string arg     (class << self; self; end).class_eval       define_method arg         arg       end     end   end end 

or little cleaner

class x   def self.attr_string arg     self.class.instance_eval       define_method(arg) { arg.to_s }     end   end end 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -