Question

When I run ruby -version I get:

ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
-e:1: undefined local variable or method `rsion' for main:Object (NameError)

What could be wrong?

Was it helpful?

Solution

Use either ruby -v or ruby --version. It's parsing the -version into rsion.

Either of these two work. Count the number of dashes:

ruby -v
ruby --version

When you provide a single dash with "version", Ruby sees this:

ruby -v -e rsion

OTHER TIPS

There is a -v option and a --version option, but no -version option. (Count the dashes.) Look undefined local variable or method 'rsion' for main:Object.

From this thread, actual reason is much clear :

If you run ruby -version, since you only use a single dash, the word 'version' isn't treated as a single flag but instead as a list of flags. In this case, it picks up the -v flag, which prints the version information. Then it tries to process the e flag, which basically says "the rest of this line is a ruby script to execute." So ruby faithfully attempts to parse "rsion", which is where you're getting the NameError.

To just get the version info, you can do ruby -v or ruby --version.

That's just the way the interpreter is but you have constants defined in Ruby also.

Try

$> ruby -e " p RUBY_VERSION"

You can find then under Module.constants

here

>> Module.constants.sort.each do |constant| 
?>   puts constant
>> end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top