tags:

views:

59

answers:

3
$: = '/users/joecool/rubylib'
$: << '/users/joecool/rubylib'
$:.unshift('/users/joecool/rubylib')
ruby -c somescript.rb    
ruby -e "puts 'Hello, world!'

Can someone direct me to some reading, so that I can figure out what this code does?

+4  A: 
$: = '/users/joecool/rubylib' 

Sets the load path to that string.

$: << '/users/joecool/rubylib'

Adds that string to the end of the load path array.

$:.unshift('/users/joecool/rubylib')

Adds that string to the beginning of the load path array.

ruby -c somescript.rb

Checks the syntax then exits.

ruby -e "puts 'Hello, world!'

Runs that Ruby snippet. See this reference and the man page.

Matthew Flaschen
So basically it does not makes much sense? :)
willcodejavaforfood
@will, it wouldn't make sense to do all of them.
Matthew Flaschen
+2  A: 

For general ruby workings, look at the Pickaxe book (The Pragmatic Programmer's Guide) http://ruby-doc.org/docs/ProgrammingRuby/

For reference about Ruby objects and functions http://ruby-doc.org/

For the precise questions, you may want to take a look at a list of predefined variables. http://www.tutorialspoint.com/ruby/ruby_predefined_variables.htm $: is the load path, an array containing directories where libraries are searched for. It's a less readable version of $LOAD_PATH.

For arguments to the interpreter, you may want to look at the unix manpage for ruby (use 'man ruby', or look at http://linux.die.net/man/1/ruby if you don't have a unix system in handy).
Specifically :
-c checks the syntax of the script without running it.
-e takes a string that is used as the script, instead of reading the script from a file.

More extensive reading : http://www.ruby-lang.org/en/documentation/

Jean
Thank you very helpfull
A: 

It looks like you need an introductory book about Ruby. There are many, but I would recommend that you take a look at Beginning Ruby by Peter Cooper or Programming Ruby by Dave Thomas. (Those two are different enough in style and organization that one or the other is likely to fit you reasonably well.)

Telemachus