-11

I am getting this issue with some of my code.

scraper.rb:14:in `block (2 levels) in scrape_movieinfo':  undefined method `slice!' for nil:NilClass (NoMethodError)
        from /usr/local/rvm/gems/ruby-2.3.1/gems/nokogiri-1.10.1/lib/nokogiri/xml/node_set.rb:238:in `block in each'
        from /usr/local/rvm/gems/ruby-2.3.1/gems/nokogiri-1.10.1/lib/nokogiri/xml/node_set.rb:237:in `upto'
        from /usr/local/rvm/gems/ruby-2.3.1/gems/nokogiri-1.10.1/lib/nokogiri/xml/node_set.rb:237:in `each'
        from /home/empathetic-file-5230/temporary/Project1/Best50Films2018/lib/Best50Films2018/scraper.rb:12:in `block in scrape_movieinfo'
        from /usr/local/rvm/gems/ruby-2.3.1/gems/nokogiri-1.10.1/lib/nokogiri/xml/node_set.rb:238:in `block in each'
        from /usr/local/rvm/gems/ruby-2.3.1/gems/nokogiri-1.10.1/lib/nokogiri/xml/node_set.rb:237:in `upto'
        from /usr/local/rvm/gems/ruby-2.3.1/gems/nokogiri-1.10.1/lib/nokogiri/xml/node_set.rb:237:in `each'
        from /home/empathetic-file-5230/temporary/Project1/Best50Films2018/lib/Best50Films2018/scraper.rb:8:in `scrape_movieinfo'
        from /home/empathetic-file-5230/temporary/Project1/Best50Films2018/lib/Best50Films2018/cli.rb:6:in `run'
        from bin/Best50Films2018:3:in `<main>'
sawa
  • 165,429
  • 45
  • 277
  • 381

2 Answers2

2

Next time you make a question showing an error like this, please show the code. You commented "Here's the code." but the only code is an error message.

Based on by very limited knowledge of Ruby, your error shows that you aren't trying to call a private method, otherwise it would give you an error like this.

private method encrypt' called for #<Person:0x007fa179863770 @name="Ada"

The method seems to be undefined. Has it been made? "undefined method" error ruby I really don't know how to answer this, there isn't much information, and I'm pretty sure that this question can't be answered without actually showing the code.

It might be that you are using the ‘slice!’ without any arguments.

It’s like making a method that accepts 1 variable(argument), but you called it with none.

FailingCoder
  • 757
  • 1
  • 8
  • 20
1

The first line of the error message tells you that: In line 14 in your scraper.rb you call the slice! method on something that is nil.

What this usually means: slice! is a method that is defined for several different types of objects – for example: String, Hash, Array. Seems like in scapper.rb:14 you think you have a variable with an instance of one of these objects, but in fact, the variable is nil.

Because you haven't posted your code nobody will able to tell you what went wrong and how to fix that. I suggest looking at the place at which you assign something to this variable. Or look if there is a simple typo in the variable name.

spickermann
  • 100,941
  • 9
  • 101
  • 131