[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Q: variable "declarations"

Ilja Tabachnik

3/17/2006 7:49:00 AM


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.

6 Answers

Farrel Lifson

3/17/2006 11:02:00 AM

0

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/...


Jenda Krynicky

2/28/2007 1:34:00 PM

0

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-....

Daniel Berger

2/28/2007 5:47:00 PM

0

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


Neville Franks

2/28/2007 11:12:00 PM

0

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-fo...

--
Posted via http://www.ruby-....

The Peeler

8/23/2013 3:31:00 PM

0

On Fri, 23 Aug 2013 07:54:47 -0700, The Rectum, the housebound resident
psychopath of sci and scj, FAKING his time zone again and IMPERSONATING his
master, The Peeler, wrote:

>>
>>???????...
>
> No duckspeak on these groups, quacking dumb Grik duck!

Keep your STENCH out of newsgroups meant only for HUMANS, you abnormal
stinking Serb rat!

--
Goran Radavich, aka "The Rectum", finally located in London:
'Fatberg' weighing 15 TONNES found blocking sewers under streets of London
Repugnant mass of congealed rotting fat and other sickening waste found.
Sewage workers have never seen the likes of the mass - as big as a bus
It could have sent sewage surging onto the streets of south London.
http://www.dailymail.co.uk/news/article-2385168/London-Fatberg-weighing-15-TONNES-blocking-sewers.html#ixz...

The Peeler

10/12/2013 11:01:00 AM

0

On Fri, 11 Oct 2013 16:17:36 -0700, The Rectum, the traumatized housebound
resident psychopath of sci and scj, FAKING his time zone again and
IMPERSONATING his master, The Peeler, wrote:

> On Fri, 23 Aug 2013 17:31:05 +0200, The Peeler
> <finishingoff@themoronicRevd.invalid> wrote:

Aug 23rd??? BRUAHAHAHAHAHAHAHAHAHAHAHAHAHAAAA...!!!

STILL hurting because of my SEVEN WEEKS old posts!

WONDERFUL!!!! HAHAHAHAHAHAHAHAAAA!!!

--
The Rectum about himself:
"And you just wish someone, anyone, anything would cornhole you!"