Wednesday 8 June 2016

RDoc and Option Parsing - Ruby on the Command Line

Hi Readers,

Today we are going to learn RDoc and Option Parsing, means ruby documentation and their options. In this we are also using ruby in command line.

RDoc and Option Parsing:

#!/usr/bin/env ruby 
# == Synopsis 
# This script takes photographs living locally on my desktop or laptop 
# and publishes them to my homepage at http://marklunds.com. 

# == Usage 

# Copy config file publish-photos.yml.template to publish-photos.yml and edit as appropriate. 
# ruby publish-photos [ -h | --help ] <photo_dir1> ... <photo_dirN> 
 
# Load the Rails environment 
require File.dirname(__FILE__) + '/../config/environment' 
require 'optparse' 
require 'rdoc/usage' 
 
opts = OptionParser.new 
opts.on("-h", "--help") { RDoc::usage('usage') } 
opts.on("-q", "--quiet") { Log::Logger.verbose = false } 
opts.parse!(ARGV) rescue RDoc::usage('usage')   

Ruby on the Command Line:

# Query and replace 
ruby -pi.bak -e "gsub(/Perl/, 'Ruby')" *.txt 
 
# Grep 
ruby -n -e "print if /Ruby/" *.txt 
ruby -e "puts ARGF.grep(/Ruby/)" *.txt

Hope you will get this concepts.
Share this page. Place comment on it.

No comments:

Post a Comment

My Experience in RUBYCONF INDIA 2016

Hi Readers, Rubyconf India is a global event complementing other RubyConf events across the world. I attended this event held on 19-20 ma...