To change directory inside a ruby script?

Don't listen to them, Dir.chdir("dir") will probably do the wrong thing. What you almost always want is to limit change to a particular context, without affecting the rest of the program like this:

#!/usr/bin/env ruby
system "rails new my_app"
Dir.chdir("my_app") do
  system "rails server &"
end
# back where we were, even with exception or whatever

Use Dir.chdir:

Dir.chdir "my_app"