Q: variable "declarations"

Hi All !

I'm new to Ruby so my question could look a bit... hmmm.. stupied.
However I do did a search in comp.lang.ruby archieves and
found a lot of questions similar to the my one - but no definite
answer. Reading Programming Ruby also didn't help.

I really don't understand how one could find errors (typos) in
variable names, like in this example:

def do_something(arg)

  result = 1
  
  # some code...

  if some_condition
    reslt = 2 # a typo here!!!
  endif
  
  # more code ...
  
  result
end

The code above is OK for Ruby - even no warnings. I could spend
hours or even days finding out why the damn thing doesn't work!
(given there are many thousands lines of code)

So I'd like to ask - is there really no way do somehow "declare"
local variable (like "use strict" and "my" in Perl)? If no, what's
"The Right Way" to deal with such situations in Ruby?

Many thanks in advance,

Ilja.

I would suggest unit tests using the Test::Unit API which comes
standard with ruby these days.

C:\>more test.rb
require 'test/unit'

def do_something
  result = 1
# some code...
reslt = 2 # a typo here!!!
result
end

class MyTestCase < Test::Unit::TestCase
  def test_do_something
    assert_equal(2,do_something)
  end
end

C:\>ruby test.rb
Loaded suite test
Started
F
Finished in 0.031 seconds.

  1) Failure:
test_do_something(MyTestCase) [test.rb:12]:
<2> expected but was
<1>.

1 tests, 1 assertions, 1 failures, 0 errors

More info at http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/

Farrel Lifson wrote:

I would suggest unit tests using the Test::Unit API which comes
standard with ruby these days.

I would suggest using a programming language.

···

--
Posted via http://www.ruby-forum.com/\.

That seems like a rather snarky reply, coming nearly a year (!) after
the original post.

I assume this is the Jenda Krynicky of ActiveState/Perl fame?

Dan

···

On Feb 28, 6:34 am, Jenda Krynicky <j...@cpan.org> wrote:

Farrel Lifson wrote:
> I would suggest unit tests using the Test::Unit API which comes
> standard with ruby these days.

I would suggest using a programming language.

Daniel Berger wrote:

···

On Feb 28, 6:34 am, Jenda Krynicky <j...@cpan.org> wrote:

Farrel Lifson wrote:
> I would suggest unit tests using the Test::Unit API which comes
> standard with ruby these days.

I would suggest using a programming language.

That seems like a rather snarky reply, coming nearly a year (!) after
the original post.

I assume this is the Jenda Krynicky of ActiveState/Perl fame?

Dan

I touched on the issue of lack of variable declarations in my short
crtique here:
http://blog.surfulater.com/2007/02/21/write-ruby-code-faster-with-ed-for-windows/

--
Posted via http://www.ruby-forum.com/\.