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
Post a Comment