I have been asked to develop a simple command line Ruby application that retrieves results from an external API with a specified search query. I have created a script to do that and made it executable using
$> ./sampleapp some_argument
$> sampleapp some_argument
def search(query ="")
...some code here ...
if ARGV.size == 0 || ARGV.strip == ""
puts "Please provide search query as an argument"
query = ARGV.strip
If this script does not depend on any 3rd party library (what is unlikely) and runs smoothly with system
ruby, the easiest way would be to copy it to
sudo cp ./sampleapp /usr/local/bin/
If it depends on other libraries, the preferred way would be to build a gem out of it, and install it with system
ruby. There are many tutorials on how to produce a
gem, the canonical one is likely this.