#define like with ruby

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 ?

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…

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

phlip wrote:

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…