From: Peter Bunyan Date: 2007-12-06T02:30:12+09:00 Subject: Keeping variables across requires? I'm making a Befunge interpreter in Ruby - I like to keep my brain active. I want to be able to switch between different sets of rules, so as well as my base program befunge.rb, I've got a file called befunge-93.rb that contains the Befunge-93 specification. Like so: befunge.rb --- instructions = {} require 'befunge-93' --- befunge-93.rb --- instructions = {} instructions["+"] = lambda { |a, b| stack.push a+b } instructions["-"] = lambda { |a, b| stack.push b-a } more instructions, snipped. --- I do the 'instructions = {}' line twice, as it curls up and dies without it. But after I've included the instructions file, instructions is still {}. This hints at the fact that it's not letting me use the instructions variable across the file. Is there any way to do this? I *could* do something like: File.open("befunge-93.rb").each { |instruction| eval(instruction } But it that's a valid solution, then I'm Tony Blair. -- Posted via http://www.ruby-forum.com/.