From: phlip Date: 2008-07-14T20:35:29+09:00 Subject: Re: #define like with 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... -- Phlip