Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to return nil message to user but not interrupt the app in ruby?

I’m trying to find a way to write in GUI for user that there is nothing in the button they just clicked

I’ve tried a method like `

if @album[@user_choice_album].tracks[10].name == nil
                return 

`
But it interrupt the program and gave an message instead, while i was expecting it to interrupt the procedure and go to the next one.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

test.rb:192:in `draw_now_playing': undefined method `name' for nil:NilClass (NoMethodError)

            if (!(@album[@user_choice_album].tracks[10].name))\

>Solution :

It looks like you have tracks stored in an array (without knowing any details about your data structure and model). And when the user requests a track that doesn’t exist, it returns nil.

That means there is no point in asking if the name of that track is nil when the whole track is nil.

I guess this should work for you:

if @album[@user_choice_album].tracks[10].nil?
  return 

Or simplified:

return unless @album[@user_choice_album].tracks[10]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading