samsymons / RedditKit.rb

[Deprecated] A Ruby wrapper for the reddit API
https://redditkit.com/
MIT License
152 stars 26 forks source link

Comment.replies? returns NoMethodError: undefined method `empty?' for nil:NilClass #26

Closed felipekk closed 9 years ago

felipekk commented 9 years ago

Hi there, While trying to iterate through all the comments in a thread, I'm getting the error NoMethodError: undefined methodempty?' for nil:NilClass`.

Example (using rails console):

irb(main):024:0> c = RedditKit.comments "2g240u"   
# the whole json...
irb(main):025:0> c.replies?  
=> true                                          
irb(main):026:0> c.replies[0].replies?
=> true 
irb(main):027:0> c.replies[0].replies[0].replies? 
=> true
# keep going until you reach the last comment that doesn't have child comments
irb(main):028:0>  c.replies[0].replies[0].replies[0].replies[0].replies[0].replies[0].replies?
NoMethodError: undefined method `empty?' for nil:NilClass                                        

I would expect the last command to return false instead of an exception. The line that throws the error is this one btw redditkit (1.0.1) lib/redditkit/comment.rb:40:inreplies'`.

felipekk commented 9 years ago

Looking at the code you probably wanted to call blank? instead of empty? since the method blank? exists in both Array and nil classes.

samsymons commented 9 years ago

Closing this as your pull request fixed the issue. Thanks again!