Tech Magazine

How to Run a Ruby Script

Posted on the 05 April 2013 by Sandislin @ed_republc
Although I had some previous programming experience from high school and college, one of the biggest gaps in my knowledge was how to actually deploy a web app or run a script. I spent several hours yesterday struggling with my Ruby environment configuration and the final solution was not at all intuitive.
Here's what I wish I knew going into it:
  • It's easier to get started on a Mac. There were several answers on StackOverflow that were way simpler for Mac users, perhaps because it's a more standardized platform. Plus, the Apple OS seems to have several built-in Ruby integrations that make things easier.
  • IRB (Interactive Ruby Shell) is not the same thing as your Ruby environment. IRB is a command line tool and your Ruby environment is executed through your choice of text editor (I'm using Sublime Text). In my case, I was able to run my script in IRB but not in Sublime Text.  Bizarre.
  • Google Searches and StackOverflow are your friends. Start with Googling (or Bing'ing) your error message - it'll probably lead you to StackOverflow. There's a good chance someone else has had the same problem, or it's linked in the related questions on the right hand side.
  • But many 'solutions' are difficult to understand and apply. From web searching, I was able to figure out that my problem was that IRB was using a different gem path than my text editor. The solutions were either 'install RVM and everything will work like magic' or change environment variables (which I couldn't find step-by-step instructions for). I'd already installed RVM, so was at a loss to understand the solution.

I eventually tried uninstalling and reinstalling Sublime Text, which magically fixed the problem. I really can't explain why this worked, but I had a gut feeling that perhaps my original installation of Sublime Text was mapping to old Ruby gem paths. Which leads me to my final conclusion...
  • Ruby is magic. If it works, just go with it. I usually try to understand the exact details of anything I'm doing. In this case, setting up Ruby is way too complex for me to fully understand. But hey, if it works, that's all I really need.

As a side note, there might be some kind of product idea here. Installing software shouldn't be so hard. But it's probably not a good business idea since, among other reasons, Ruby resources are generally free.

Back to Featured Articles on Logo Paperblog

Paperblog Hot Topics

Magazine