0

When I try to open A ruby file in the same directory something weird happens, like so :

C:\RubyFiles>file = File.open("Lottery.rb", "r") 'file' is not recognized as an internal or external command, operable program or batch file.

now I know this has nothing to do with the opening of the file itself, but I wanted to have an example ;)

(This has been resolved^) :D

But now I would like to know how to run the file itself? Can anyone help? Thanks in advance!

1 Answers1

0

After opening irb, you can execute a ruby file using Kernel#load

load 'Lottery.rb'

If this file just includes module/class definitions, you probably only want to load it once. This is what Kernel#require ensures:

require 'Lottery.rb'
Cameron Martin
  • 5,952
  • 2
  • 40
  • 53
  • Why can't I used the variables that are in the file to make operations outside of the methods I've already defined(in the file)? I'm trying to return parts of a method, to see if the data was processed the way I want it to. – Damien Robichaud Aug 22 '14 at 01:07
  • Variables declared inside files are not accessible outside the scope of that file. See http://stackoverflow.com/questions/2699324/ruby-irb-requires-and-scope – Cameron Martin Aug 22 '14 at 01:24