I
Ian FalsePositives
In a (doomed?) attempt to actual understand ruby (with my almost 20
years of coding experience), I'm working my way thur "Why's
(Poignant) Guide to Ruby", chapter 4 "Floating Little Leaves of Code"
and doing the "Making the Swap" section example. (on a Win XP box)
and although the "require" loads the wordlist.rb file to load using the
require 'wordlist' method, I was getting "undefined local variable or
method `code_words' for main:Object (NameError)" WTF?!!
the wordlist.rb was :
code_words = {
'starmonkeys' => 'Phil and Pete, those prickly chancellors of the
New Reich',
'catapult' => 'chucky go-go', 'firebomb' => 'Heat-Assisted Living',
'Nigeria' => "Ny and Jerry's Dry Cleaning (with Donuts)",
'Put the kabosh on' => 'Put the cable box on'
}
and, to make it an even simpler example, the calling file was
# SimReq.rb to test require loading
require 'wordlist'
code_words.each {|key, value| print "Key:", key, " for Value:", value,
"\n" }
Just get the require file and do something with the the variable
"Code_words".
I got around the "undefined local variable" by making code_words global
with "$" on "Code_words" in both files. (i.e. "$code_words")
So was it a scoping problem?
Is there a better, or best practice, to do something like this trivial
example or is this Chunky Bacon payback for actually doing the
examples? Or someOther PEBKAC issue?
Please advise O' Great and Powerful OZ!..I mean comp.lang.ruby....
Ian
www.FalsePositives.com
years of coding experience), I'm working my way thur "Why's
(Poignant) Guide to Ruby", chapter 4 "Floating Little Leaves of Code"
and doing the "Making the Swap" section example. (on a Win XP box)
and although the "require" loads the wordlist.rb file to load using the
require 'wordlist' method, I was getting "undefined local variable or
method `code_words' for main:Object (NameError)" WTF?!!
the wordlist.rb was :
code_words = {
'starmonkeys' => 'Phil and Pete, those prickly chancellors of the
New Reich',
'catapult' => 'chucky go-go', 'firebomb' => 'Heat-Assisted Living',
'Nigeria' => "Ny and Jerry's Dry Cleaning (with Donuts)",
'Put the kabosh on' => 'Put the cable box on'
}
and, to make it an even simpler example, the calling file was
# SimReq.rb to test require loading
require 'wordlist'
code_words.each {|key, value| print "Key:", key, " for Value:", value,
"\n" }
Just get the require file and do something with the the variable
"Code_words".
I got around the "undefined local variable" by making code_words global
with "$" on "Code_words" in both files. (i.e. "$code_words")
So was it a scoping problem?
Is there a better, or best practice, to do something like this trivial
example or is this Chunky Bacon payback for actually doing the
examples? Or someOther PEBKAC issue?
Please advise O' Great and Powerful OZ!..I mean comp.lang.ruby....
Ian
www.FalsePositives.com