Forum: Ruby undefined method error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4c1b1c63b81fe7c9f09128674b7c2da6?d=identicon&s=25 Kenny Andrews (puef)
on 2014-07-17 14:19
so im trying to compile a bot for a video game and it gives me undefined
method error for a certain script and i have no idea who to fix it.

im getting this build_tools/process_files.rb:70:in `generate_version':
undefined method `[]' for nil:NilClass (NoMethodError)
  from build_tools/process_files.rb:61:in `generate_build_information'
  from build_tools/process_files.rb:142:in `block in <main>'
  from build_tools/process_files.rb:55:in `initialize'
  from build_tools/process_files.rb:139:in `new'
  from build_tools/process_files.rb:139:in `<main>'
build_tools/process_files.rb Starting...
Command /bin/sh failed with exit code 1

the piece of code is

def generate_version
            game_version =
                (@build_information[:kind] == "CVS") ?
"#{TOP_LEVEL}").chomp :
VERSION "(.*)"/)[0][0]
= game_version

if anyone could help that was be awesome.
5c4e55b92169c16ce2ca8fd75318eded?d=identicon&s=25 David Unric (dunric)
on 2014-07-17 15:29
You didn't posted where is the row Nr. 70 but from the code I'd suspect
the issue is with @build_information instance variable is not
initialized - ie its value is nil, therefore sending `[]' method fails
with exception.
4c1b1c63b81fe7c9f09128674b7c2da6?d=identicon&s=25 Kenny Andrews (puef)
on 2014-07-17 15:39
oh sorry line 70 is"#{TOP_LEVEL}/src/macosx/").scan(/"#define
VERSION "(.*)"/)[0][0]
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-07-17 20:53
Test the output of this:"#{TOP_LEVEL}/src/macosx/").scan(/"#define
VERSION "(.*)"/)

It looks like it isn't finding any matches, so when you try to access
the object in index zero with [0][0], it tells you that #[] is not
defined on NilClass, because there's nothing in the array.
5c4e55b92169c16ce2ca8fd75318eded?d=identicon&s=25 David Unric (dunric)
on 2014-07-17 21:08
So it's clear now. File <top level>/src/macosx/ does
not contain expected pattern "#define VERSION "(.*)" .

First I'd make sure whether all double-quotes in /"#define VERSION
"(.*)"/ are correct. I'd bet the first one before #define is accidental
and may need to be removed.
Second open the `' file in an editor and look for a row
containing VERSION macro definition and check the current format and
adjust the regexp pattern accordingly. If in troubles you may paste the
corresponding line here.
This topic is locked and can not be replied to.