Skip to content

Instantly share code, notes, and snippets.

@trevrosen
Last active November 18, 2015 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevrosen/653282fc5717c2ab5bdd to your computer and use it in GitHub Desktop.
Save trevrosen/653282fc5717c2ab5bdd to your computer and use it in GitHub Desktop.
How MRI Ruby's ARGV really works
# The docs say that ARGV[0] should be the name of the Ruby executable.
# http://ruby-doc.org/core-2.2.3/Object.html#ARGV
#
# This is **NOT** how Ruby actually behaves:
─trevorrosen@Saramago ~
╰─$ cat argv-test.rb
#!/usr/bin/env ruby
p ARGV[0]
╭─trevorrosen@Saramago ~
╰─$ ruby argv-test.rb
nil
╭─trevorrosen@Saramago ~
╰─$ ruby argv-test.rb foo
"foo"
╭─trevorrosen@Saramago ~
╰─$ ./argv-test.rb
nil
╭─trevorrosen@Saramago ~
╰─$ ./argv-test.rb foo
"foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment