From: Johan Eriksson Date: 2008-04-28T19:37:24+09:00 Subject: Re: undefined local variable Hi -- This is what I've got now. the_class.class_eval <<-EOA def self.load_from_file(filename) yaml_dict = YAML::load(File.open(filename)) object_list = yaml_dict[yaml_dict.keys[0]].map do |from_file| puts "from_file: #{from_file}" new_obj = self.class.new from_file.map do |obj| puts "obj: #{obj}" obj_as_list = obj.to_a puts "obj_as_list: #{obj_as_list}" if obj_as_list[1].is_a? String obj_as_list[1] = "'#{obj_as_list[1]}'" end str = "new_obj.#{obj_as_list[0]} = #{obj_as_list[1]}" eval(str) end new_obj end object_list end EOA It gets me this: undefined local variable or method `from_file' for main:Object If I do the same thing outside of a class_eval it works fine, but I need to add it to a class I have just generated. Why does it not recognise the variable. Any help is much appreciated! /Johan