From: Koos Brandt Date: 2007-10-19T23:16:18+09:00 Subject: Eval alternative to execute string I have the following stored in a file Example1.rb require 'rubygems' require 'wx' include Wx require 'wx_sugar/all' class ExampleApp < App def on_init frame = Frame.new( nil, :title => "Example1.rb" ).show end end ExampleApp.new.main_loop() If I run the following snippet, it works mycontents = IO.read(File.dirname(__FILE__)+ "/testSources/Example1.rb") eval mycontents if I however create a class and do the eval from inside the class, I get an error that ‘include’ is not a method of Document. class Document def initialize() @content = "" # this is the actual content of the document end # eval the text content def run eval @content end # load the file from disk and put it into @content def load @content = IO.read(File.dirname(__FILE__)+ "/testSources/Example1.rb")) puts @content end end myProg = Document.new() myProg.load myProg.run If I however include in the class file the requires and includes, and comment them out in Example1.rb, then it also works. require 'rubygems' require 'wx' include Wx require 'wx_sugar/all' The story about eval I take note of, but I think it is clear what I want to to here: read a file and execute it. From what I see above, this is not entirely what eval will do for me. Eval makes the source file part of the current executing environment. What I actually want to do is: ruby “big piece of text” and that should not be part of my current environment if you understand what I mean. -- Posted via http://www.ruby-forum.com/.