tags:

views:

36

answers:

4

I want to run:

> ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29034) [x86_64-darwin10.4.0]

and then see if 1.9.2 is printed out. If so, i return true.

How would this method look like using a regexp?

+1  A: 

RUBY_VERSION == "1.9.2"

John Douthat
haha awesome..ok if i want to use a regexp match then just out of curiosity? good to know when there is no constant defined.
never_had_a_name
+1  A: 

I'd recommend using 'RUBY_VERSION', however you could do something like:

`ruby --version`.include? "1.9.2"
Kevin Sylvestre
A: 

Maybe I am off the track here but you do seem to want to check the version from the shell ? Something like this then will do it.

export VERSION=`ruby --version | grep 1.9.2`
if [[ -n "$VERSION" ]] ; then
  echo "you have the right version yay!"
else
  echo "bummer dude ><!"
fi
Hugo
A: 

The regex for this is simply

/1.9.2/

So

s=`ruby --version`
return true if s=~/1\.9\.2/

(updated)

shreddd
You need to escape the `.`'s otherwise `19992` etc. match too
gnibbler