Hi
I wasn''t clear this was a question about wxRuby, or just a general Ruby
question. If it''s the latter, it''s better directed to
comp.lang.ruby
newsgroup / ruby-talk mailing list.
Jason Shelton wrote:> It seems that Ruby has a problem with using variables in certain
> scenarios.
Don''t take this the wrong way - but if Ruby had a defect by which it
randomly changed the value of variables under your nose, someone would
probably have run into it before and reported it...
> Previously, I was passing a parameter to a class named
''Test'' with a
> function in it named ''go''. This is the syntax that I
used,
> Test.new.go(''hello'') The function ''go''
would open a .xls file with
> the parameter in the path, such as C:\hello\data.xls. Everything was
> working fine then. Now, instead of using the actual string
''hello'' as
> the parameter, I am using an array element variable, so the syntax is
> Test.new.go(array[x]). Now the ''go'' function throws the
''''File not
> found'' error. In the error message, both the path and file are
> correct, so I do not understand why the file cannot be found.
Hard to know what might be going on without sight of the code. There
*must* be some difference between the literal string ''hello''
and the
array element.
Things to suspect are: the array index ''x'' doesn''t
point to a valid
member; the input value array[x] is not what you expect - perhaps it
contains spaces or newlines or wrong-case characters so that it doesn''t
stand out as wrong; the ''go'' method is altering the parameter
in some
unanticipated way.
I would recommend writing some tests for your class, so you can verify
your assumptions about how that class works with different input. Give
it both correct and incorrect input parameters, to check that it works
in the first case and fails gracefully in the second. Writing tests can
also help structure your code better; specifically to GUI code, it can
help identify where too much application logic is being moved into the
GUI layer. There are numerous testing frameworks for ruby; personally I
find ''test/unit'', included by default with Ruby, does
everything I need,
but you may wish to explore other options (eg rspec).
hth
a