Passing commandline parameter (arguments) to ruby file using optparser

Ruby file accepts from command prompt in the form of array.Passing parametersruby input.rb TOI DH TimesNewAccessing parameters # input.rb p ARGV # => ["TOI", "DH", "TimesNew"] p ARGV[0] # => "TOI" p ARGV[1] # => "DH"Optparser : parses commandline options in more effective way using OptParser class.and we can access options as hashed parameters.Passing parametersruby … Continue reading Passing commandline parameter (arguments) to ruby file using optparser

Variables initialization, assignments and swapping in ruby

Just a single line variable swap in rubyx,y=y,xExample:irb>> x = "Fun"=> "Fun"irb>> y = "Rails"=> "Rails"irb>> x,y = y,x=> ["Rails", "Fun"]irb>> p x"Rails"=> nil>> p y"Fun"Variable assignments in Rubywe can do multiple assignments in a single line.irb>> a,b,c,d = 1,2,3,4=> [1, 2, 3, 4]here is interpretation of above lineirb>> p "a => #{a} b => #{b} … Continue reading Variables initialization, assignments and swapping in ruby