[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

#define like with ruby

Jyri Vesalainen

7/14/2008 9:58:00 AM

My code snippet looks like:
...
testdata[current_line + 1] ...
...

I would like to replace current_line + 1
with something more desciptive like NEXT_LINE.

In C I would do:
#define NEXT_LINE current_line + 1

Is there something similar like #define in Ruby ?
--
Posted via http://www.ruby-....

3 Answers

Phlip

7/14/2008 11:34:00 AM

0

Jyri Vesalainen wrote:
> My code snippet looks like:
> ..
> testdata[current_line + 1] ...
> ..
>
> I would like to replace current_line + 1
> with something more desciptive like NEXT_LINE.
>
> In C I would do:
> #define NEXT_LINE current_line + 1

Just a C tip: I thought C supported global constants, enums, and inline
functions. Never use #define if you have any alternative. And if you do, put
parens around (current_line + 1), to avoid conflicts in operator precedence.

> Is there something similar like #define in Ruby ?

(Roughly) everything beginning with a capital letter is a constant.

Make @current_line into an instance variable of your current object, and use:

def next_line
@current_line + 1
end

But there are far better ways to iterate a Ruby array...

--
Phlip

Jyri Vesalainen

7/14/2008 12:05:00 PM

0

Thanks a lot!
ps.
My C-code was just a example(obviously bad one).

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

Phlip

7/14/2008 1:51:00 PM

0

Jyri Vesalainen wrote:
> Thanks a lot!
> ps.
> My C-code was just a example(obviously bad one).

Sorry. If you questions for a decade on news:comp.lang.c++ , certain things
start to rub off...