Ruby IRB - Requires and Scope
Posted
by tyndall
on Stack Overflow
See other posts from Stack Overflow
or by tyndall
Published on 2010-04-23T14:27:23Z
Indexed on
2010/04/23
15:13 UTC
Read the original article
Hit count: 495
Trying to understand this problem I'm running into.
I create file welcome.rb. The contents of this file:
welcome_message = "hi there"
I then launch an irb session.
And type require 'welcome'. That works fine.
Then I type:
puts welcome_message
I get the error message undefined local variable or method `welcome_message' for main:Object
What is the best way to bring in predefined variables and have initialization work done when you require something into your irb session. Global variables didn't seem like the right path.
© Stack Overflow or respective owner