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.
Af08edc9c8f78e83c4f2a25a48dae8b6?d=identicon&s=25 Kenny A. (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.
5d303cc273a7e8784a7f243b2cec5c28?d=identicon&s=25 David U. (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.
Af08edc9c8f78e83c4f2a25a48dae8b6?d=identicon&s=25 Kenny A. (puef)
on 2014-07-17 15:39
oh sorry line 70 is"#{TOP_LEVEL}/src/macosx/").scan(/"#define
VERSION "(.*)"/)[0][0]
9627ec27e4fb3a18be02133b4ddaa901?d=identicon&s=25 Joel P. (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.
5d303cc273a7e8784a7f243b2cec5c28?d=identicon&s=25 David U. (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.