makersacademy / learn_to_program

For submitting exercises from the Chris Pine Learn to Program Book
11 stars 400 forks source link

Codewars Problem - Method evaluating to nil #498

Closed liamtlr closed 8 years ago

liamtlr commented 8 years ago

Coming to the end of a really beasty beta kata on codewars (https://www.codewars.com/kata/57b2fc418491f9f092000029/train/ruby ).

Essentially it is about deciphering a coded text based on a number of cyphers contained in hashes, as well as somme additional rules that need to be accounted for.

As part of the additional rules, I've created some statements to evaluate for these rules / exceptions. These for the most part work, apart from one which is supposed to take into account the awkwardly worded 'characters different than a letter' which may or may not follow a character..

After some googling I managed to steal someone else's code (that's allowed right, ?! ^-^), using a regex statement - see below. A nearly identical statement is used to evaluate whether the character being evaluated is a number (0-9). However, for the one shown I am getting an

'undefined method `[]' for nil:NilClass (NoMethodError)'.

I assume this means that the statement is evaluating to nil and the script doesn't know what to do in this case. My question therefore is thus:

1) Why does it evaluate to nil , as opposed to false? 2) How do I get around it!?

Any guidance / sympathy is much appreciated! Also this is my first issue so if I've worded it poorly / clumsily and you have any pointers than equally helpful! This is the last thing I need to pass the kata and I neeeeeed these points!

Cheers screen shot 2016-09-10 at 14 35 56

nikeshashar commented 8 years ago

Hey - please open this on the PreCourse repo to get support correctly. Thanks.

liamtlr commented 8 years ago

Thanks for the pointer!