From: Mike Stok Date: 2013-06-23T02:05:37+09:00 Subject: Re: Load error - Std lib class Dir On 2013-06-22, at 12:27 PM, Love U Ruby wrote: > Mike Stok wrote in post #1113272: > > >> In the documentation in the URL you posted it says that the tmpdir stuff >> is in the file tmpdir.rb, so you should try >> >> #!/usr/bin/env ruby >> >> require 'tmpdir' > > Thank you very much as always!! > > Why the line is needed - ` #!/usr/bin/env ruby` ? I have seen lots of > code having that line at top. I am not aware of that one. > > Could you help me ? The #! line (shebang line) specifies which interpreter to use. So a script starting with #!/usr/bin/ruby would always use the /usr/bin/ruby interpreter to run the script. As I use chruby to let myself switch between ruby scripts the ruby I want to run for my programs is pointed at by /Users/mike/.rbenv/shims/ruby, whose directory is on my PATH. When I start a script with #!/usr/bin/env ruby then the env program searches my PATH for the first ruby it finds and uses that to interpret the script. This is useful to me as it lets me easily switch versions in my shell and have the ruby version I'm interested in execute the script. It also helps when distributing a script for use on systems where you don't know if ruby is /bin/ruby, /usr/local/bin/ruby, /usr/bin/ruby, or something else - as long as the PATH is set up correctly ruby will be found. There is a downside to /usr/bin/env in that it depends on the path of the user running it, so the same script on a system run by two different users can use different interpreters. That can cause confusion when debugging. Hope this helps, Mike > > -- > Posted via http://www.ruby-forum.com/. -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply.