I have been using C for a while and I was wondering how you can tell
what the main file is in a multi file Ruby project?
Ruby is great, I love it as a language. thanks to all who take time to
post here with answers to our newb questions.
I have been using C for a while and I was wondering how you can tell
what the main file is in a multi file Ruby project?
Ruby is an interpreted language - you always execute the interpreter
by passing to it the name of a script, some inline code or code fed
via the standard input. There is no default ‘main’. The script, and
everything else that is pulled in by it, is evaluated sequentially.
Of course, the code within method definitions is not executed
immediately. But the rest is.
If you don’t actually run the interpreter yourself, chances are you
run a script that is made executable, and where the first line is
something like:
#!/usr/bin/ruby
Try this, for example:
less which irb
If you have a multi-file project, check what command you are supposed
to execute.
I have been using C for a while and I was wondering how you can tell what
the main file is in a multi file Ruby project?
Ruby is great, I love it as a language. thanks to all who take time to
post here with answers to our newb questions.
Actually its not wrong. What it does is explicitly state which ruby
interpreter to use rather than using env to determine by finding the
first
one in the path. His way in no way shape or form is wrong provided that
ruby actually lives there.
Your way is the more common way but that doesn’t make it the defacto
Right
Way™
Actually its not wrong. What it does is explicitly state which ruby
interpreter to use rather than using env to determine by finding the first
one in the path. His way in no way shape or form is wrong provided that
ruby actually lives there.
As and operations person, I will point out that using
#!/usr/bin/env ruby
is a really, really bad idea for a production system.
or on the other hand, when #!/usr/bin/ruby is used in a gem, users gets
problems because it does not work with rbenv, rvm or /usr/local builded
ruby, env can be easier changed, even in a production system
Actually its not wrong. What it does is explicitly state which ruby
interpreter to use rather than using env to determine by finding the first
one in the path. His way in no way shape or form is wrong provided that
ruby actually lives there.
As and operations person, I will point out that using
#!/usr/bin/env ruby
is a really, really bad idea for a production system. It introduces an
exepect behaviour when doing system upgrades and migrations or when
somebody changes the .profile for the account. Please don’t deploy
stuff
like that into production unless you are willing to include your phone
number and accept calls in the middle of the night for the next 5+
years.
– Matt
It’s not what I know that counts.
It’s what I can remember in time to use.
I’m interested in the issue with using env, but I find you explanation a
but hard to follow. What are some situations that lead to the problems
you are describing. I’m currently using env in some gems and if there is
a strong argument against it, I don’t mind switching it.
The simplest issue is that env uses the first ruby it finds in the PATH
variable. Now, say you’re running an application that works fine, and
uses Ruby 1.9.x specific syntax such as the new Hash syntax. Now, the
PATH gets modified and the Ruby in the path is changed to, say, Ruby
1.8.7. The application in question (script/whatever) will puke. Ruby
1.8.x doesn’t understand that new syntax.
All it took was a simple path change to break your up-to-now working
script/application, using ‘env’. If you hardwire the Ruby in the script,
the app/script will continue to work just fine. Now, that comment
presupposes that the original Ruby binary still lives in the same spot,
and hasn’t been changed. You change that binary, then all bets are
off.
There are a number of other possible scenarios, but that is the easiest
to make clear.
is a really, really bad idea for a production system.
or on the other hand, when #!/usr/bin/ruby is used in a gem, users gets
problems because it does not work with rbenv, rvm or /usr/local builded
ruby, env can be easier changed, even in a production system
No, it can’t. Been there, done that. Most developers are really smart
and are very good at solving problems when they arise. That’s a
terrible
way to run production, avoiding problems is the way to have a stable
environment. Like I said, use env and you should be on the hook for the
rest of your life for any issues that occur.
– Matt
It’s not what I know that counts.
It’s what I can remember in time to use.
I’m interested in the issue with using env, but I find you explanation a
but hard to follow. What are some situations that lead to the problems
you
are describing. I’m currently using env in some gems and if there is a
strong argument against it, I don’t mind switching it.
Question: why does a gem have a shebang line at all? Aren’t gems always
only ever required by other ruby scripts?
I suppose the problem is that osx comes with a system ruby install which
is difficult to change. In fact on osx I never want anything using
system ruby, but osx internals can rely on that ruby so I don’t want to
change it. What should one do in this situation to not use env? I’d
probably be quite upset gem publishers who used 1.9 syntax used the ruby
version in /use/bin
Interesting. How do they get added to the shell path, so you can execute
them? Or do you have to write
/usr/local/lib/ruby/gems/1.9.3/gems/foo/lib/foo-cli.rb
or whatever to actually run them?
My system ruby installs them into /usr/bin. So I get /usr/bin/rails.
When
using ruby version managers they install them into more sane locations.
You can use gem install --env-shebang <gemname> to fix this for yourself.
Interesting. How do they get added to the shell path, so you can
execute
them? Or do you have to write
/usr/local/lib/ruby/gems/1.9.3/gems/foo/lib/foo-cli.rb or whatever to
actually run them?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.