H
Howard Fine
I just started tinkering with Ruby. From "The Poignant Ruby Programmer"
or whatever it's called (you know what I mean) I tried running the small
example but get an error.
This is the first file called m2.rb:
require '/usr/home/me.rb'
# Get evil idea and swap in code words
print "Enter your new idea: "
idea = gets
code_words.each do |real, code|
idea.gsub!( real, code )
end
# Save the jibberish to a new file
print "File encoded. Please enter a name for this idea: "
idea_name = gets.strip
File:pen( "idea-" + idea_name + ".txt", "w" ) do |f|
f << idea
end
And this is me.rb:
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'
}
When I do: ruby me2.rb and enter any of the code_words above, I get:
me2.rb:6: undefined local variable or method `code_words' for
main:Object (NameError)
What am I missing?
or whatever it's called (you know what I mean) I tried running the small
example but get an error.
This is the first file called m2.rb:
require '/usr/home/me.rb'
# Get evil idea and swap in code words
print "Enter your new idea: "
idea = gets
code_words.each do |real, code|
idea.gsub!( real, code )
end
# Save the jibberish to a new file
print "File encoded. Please enter a name for this idea: "
idea_name = gets.strip
File:pen( "idea-" + idea_name + ".txt", "w" ) do |f|
f << idea
end
And this is me.rb:
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'
}
When I do: ruby me2.rb and enter any of the code_words above, I get:
me2.rb:6: undefined local variable or method `code_words' for
main:Object (NameError)
What am I missing?