Sophrinix / TryRuby

Try Ruby is a interactive shell that quickly and whimsically teaches the Ruby programming language. Originally _why's idea, it has been recreated from the ground up by Rubyists who have a passion for Ruby and for teaching their fellow (wo)man how to program.
tryruby.org
347 stars 79 forks source link

Can't finish lesson: "In Ruby, Def Leppard Means Define Leppard (a Method)!" #106

Closed lexastudio closed 13 years ago

lexastudio commented 13 years ago

Hi,

Here is what I faced during that lesson:

def load_comics(path)
.. comics = {}
.. File.foreach(path) do |line|
.. name, url = line.split(': ')
NameError: undefined local variable or method `line' for main:Object

def load_comics(path)
.. comics = {}
.. File.foreach(path) do |line|
.. name, url = line.split(': ')
.. comics[name] = url.strip
NoMethodError: undefined method `strip' for nil:NilClass

def load_comics(path)
.. comics = {}
.. File.foreach(path) do |line|
.. name, url = line.split(': ')
NameError: undefined local variable or method `line' for main:Object

def load_comics(path)
.. comics = {}
.. File.foreach(path) do |line|
.. name, url = line.split(': ')
.. comics[name] = url.strip
NoMethodError: undefined method `strip' for nil:NilClass

def load_comics(path)
.. comics = {}
.. File.foreach(path) do |line|
.. name, url = line.split(': ')
.. comics[name] = url.strip
.. end
.. comics
.. end
SyntaxError:

:167: syntax error, unexpected keyword_end, expecting $end

def load_comics(path)
.. comics = {}
.. File.foreach(path) do |line|
.. name, url = line.split(': ')
.. comics[name] = url.strip
.. end
.. comics
=> {}

load_comics('/Home/comics.txt')
NoMethodError: undefined method `times' for "Scott":String

load_comics('/Home/comics.txt')
NoMethodError: undefined method `load_comics' for main:Object

Please notice this error message, which is before the last one:

NoMethodError: undefined method `times' for "Scott":String

I did not enter "times" or "Scott" at all in this session. I guess there is a problem with mixing different working scopes among sessions.

Anyway, thanks for such a great tutorial!
Lexastudio

cameronmalek commented 13 years ago

I'm stuck at this part, too. Mac OS X.6.5, Chrome 10.0.612.3 dev. Here's my input/output:

>> def load_comics( path )                                              
..   comics = {}                                                        
..   File.foreach(path) do |line|                                       
..   name, url = line.split(': ')                                       
NameError: undefined local variable or method `line' for main:Object    
>> def load_comics( path )                                              
..   comics = {}                                                        
..   File.foreach(path) do |line|                                       
..     name, url = line.split(': ')                                     
..     comics[name] = url.strip                                         
NoMethodError: undefined method `strip' for nil:NilClass

There was more before this, but I think you get the idea between this and the original poster's findings as well.

cameronmalek commented 13 years ago

After trying this lesson three or four times, I couldn't get it to work. Then, naturally, after posting the above comment on this issue, it seemed to resolve itself and work the first time I tried again. D:

hugoahlberg commented 13 years ago

I'm having the same issue. NoMethodError: undefined method strip' for nil:NilClass or NameError: undefined local variable or methodline' for main:Object

Tried in both Firefox and Chrome on Mac OSX

Any tips?