[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Ruby Source code checker

Michael Gebhart

2/15/2005 1:58:00 PM

Hi,

currently I am doing my first steps with ruby. It's really great, but
sometimes I'm doing some very stupid mistakes :) I only realize this, when
running the program and starting the function, where I have done the
mistake. Is there any possibility to check the code before running it?
Because if I do not run the function, I'll never see, that there is a
error, which is followed by a crash. The problem is, that
ruby doesn't know the types, the variables have. When I do:

@variable.function

ruby does not know, if the method "function" is avaibable or not. But
nevertheless, is it possible to find out some errors without running the
program and starting the function?

Greetings

Michael
11 Answers

George Moschovitis

2/15/2005 2:04:00 PM

0

Michael Gebhart wrote:
> mistake. Is there any possibility to check the code before running it?

try:

ruby -c yourfile.rb

regards,
George.

Sea&Gull

2/15/2005 2:08:00 PM

0

Michael Gebhart wrote:
> Hi,
>
> currently I am doing my first steps with ruby. It's really great, but
> sometimes I'm doing some very stupid mistakes :) I only realize this, when
> running the program and starting the function, where I have done the
> mistake. Is there any possibility to check the code before running it?

Try "ruby -c your_script.rb"

Also try a great tool - "irb" - which is the interactive ruby.

> Because if I do not run the function, I'll never see, that there is a
> error, which is followed by a crash. The problem is, that
> ruby doesn't know the types, the variables have. When I do:
>
> @variable.function
>
> ruby does not know, if the method "function" is avaibable or not. But
> nevertheless, is it possible to find out some errors without running the
> program and starting the function?
>
> Greetings
>
> Michael

--
s&g

Christian Neukirchen

2/15/2005 4:18:00 PM

0

George Moschovitis <george.moschovitis@gmail.com> writes:

> Michael Gebhart wrote:
>> mistake. Is there any possibility to check the code before running it?
>
> try:
>
> ruby -c yourfile.rb

This answer is a bit misleading, ruby -c will only check the file for
syntactic correctness (which happens during parsing, anyway).

In general, there is no way of telling a method-lookup at runtime will
work, as Ruby is dynamically typed. Use unit-tests to ensure the
correctness of your methods.

Also, ruby -w may be useful to show up likely-to-be-problematic things
as uninitalized instance variables etc.

> regards,
> George.
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...


Bill Guindon

2/15/2005 4:28:00 PM

0

On Tue, 15 Feb 2005 23:04:57 +0900, Michael Gebhart <mail@miketech.net> wrote:

> When I do:
>
> @variable.function
>
> ruby does not know, if the method "function" is avaibable or not.

actually, you can ask it...

@variable.respond_to?("function")

--
Bill Guindon (aka aGorilla)


dblack

2/15/2005 4:57:00 PM

0

Bill Guindon

2/15/2005 5:10:00 PM

0

On Wed, 16 Feb 2005 01:57:23 +0900, David A. Black <dblack@wobblini.net> wrote:
> Hi --
>
> On Wed, 16 Feb 2005, Bill Guindon wrote:
>
> > On Tue, 15 Feb 2005 23:04:57 +0900, Michael Gebhart <mail@miketech.net> wrote:
> >
> >> When I do:
> >>
> >> @variable.function
> >>
> >> ruby does not know, if the method "function" is avaibable or not.
> >
> > actually, you can ask it...
> >
> > @variable.respond_to?("function")
>
> But that's a runtime thing too. I don't think you can leverage that
> to do pre-runtime checking.
>

Yep, but he started out mentioning a runtime problem. Just wanted to
make sure he knew he could check for the method during runtime
(triggered by "doing my first steps with ruby").

--
Bill Guindon (aka aGorilla)


dblack

2/15/2005 5:39:00 PM

0

Ryan Davis

2/15/2005 5:43:00 PM

0


On Feb 15, 2005, at 6:04 AM, Michael Gebhart wrote:

> currently I am doing my first steps with ruby. It's really great, but
> sometimes I'm doing some very stupid mistakes :) I only realize this,
> when
> running the program and starting the function, where I have done the
> mistake. Is there any possibility to check the code before running it?
> Because if I do not run the function, I'll never see, that there is a
> error, which is followed by a crash. The problem is, that
> ruby doesn't know the types, the variables have. When I do:
>
> @variable.function
>
> ruby does not know, if the method "function" is avaibable or not. But
> nevertheless, is it possible to find out some errors without running
> the
> program and starting the function?

As others have mentioned, unit testing is by far your best way to go.
Not only will it help you write more ruby code in general (increasing
your ruby-fu), but it'll prevent any problems you identify from coming
back. It is still a runtime solution, but you get to control the
environment and context. I suggest you check out ZenTest (below) to
help get you jumpstarted.

--
ryand-ruby@zenspider.com - http://blog.zens...
http://rubyforge.org/project...
http://www.zenspider.com/...



Neil Stevens

2/16/2005 12:14:00 AM

0

On Tue, 15 Feb 2005 14:57:32 +0100, Michael Gebhart wrote:
> When I do:
>
> @variable.function
>
> ruby does not know, if the method "function" is avaibable or not. But
> nevertheless, is it possible to find out some errors without running the
> program and starting the function?

Not really. That's one reason that people have developed test
frameworks. Using those, you can test individual bits of code without
having to run the whole program.

--
Neil Stevens - neil@hakubi.us

'A republic, if you can keep it.' -- Benjamin Franklin

John Carter

2/16/2005 3:22:00 AM

0