Getting the version number of the ruby interpreter

K

Keith P. Boruff

Hello all,

Is there a way to get the version number within a ruby script of the
interpreter running that script?

Yes, I know I can do this on the cmd line:
% ruby --version

I didn't seem to find anything in the documentation though I am new at
this language.

I have my reasons for wanting the version info in this manner. If you
really want to know, I'll tell you. Otherwise, I'll spare you the boring
details.

Thanks,
KPB
 
N

Nicholas Van Weerdenburg

That's no longer supported as of 1.8, but unfortunately gives no
error, according to page 64 of PickAxe2.

while line = gets
puts line if line =~ /start/ .. line =~ /end/
end

is the correct form now.

Note: gets and print still operate magically on $_ in 1.8.2 but I'm
guessing / / doesn't, and hence that example no longer working.

More in line with the original example, I'd guess that this also works:

while gets
print if $_ =~ /start/ .. $_ =~ /end/
end
# $_ implicit for gets and print

Regards,
Nick
 
N

Nicholas Van Weerdenburg

Did some testing, / / will operate on $_ implicitly, so that's not why
it no longer works as it did.

e.g.
while gets
print if /start/
end

will print the line containing start.

So I'm guessing that / / changed what it returns (Matchdata or nil)
compared to what it used to return prior to 1,8 (Fixnum or nil) and
that breaks using it by itself with ranges.

Of course, this is all considered bad form in Ruby now anyhow. Still,
it's very nice for command-line 1 lines ( ruby -n -e 'print if /ruby/'
input.txt )

Nick
 
J

James Edward Gray II

Of course, this is all considered bad form in Ruby now anyhow. Still,
it's very nice for command-line 1 lines ( ruby -n -e 'print if /ruby/'
input.txt )

Which is exactly why the old behavior still works there. ;)

james% cat test.txt
start
middle
end
james% ruby -n -e 'print unless /middle/' test.txt
start
end

James Edward Gray II
 
W

William James

Nicholas said:
while gets
print if $_ =~ /start/ .. $_ =~ /end/
end


That works. The equivalent Awk program is:

/start/,/end/

An Awk program to skip blank lines at the beginning of the file
(including lines containing only spaces)
and to print the rest of the lines:

NF,0
 
N

nobu.nokada

Hi,

At Sat, 22 Jan 2005 03:34:47 +0900,
irb(main):001:0> VERSION
=> "1.8.2"
irb(main):002:0>

Note that the constant VERSION has been obsolete. Use
RUBY_VERSION instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,440
Latest member
YoungBorel

Latest Threads

Top