As an exercise to learn Ruby, I would like to create a script that will be run from the terminal. It should accept as input either a string or a text file and it should output the result of various string parsing mechanisms that I will write myself.
To get me started, would you please translate this pseudo-code into proper Ruby for me?
- In terminal:
ruby myscript.rb(either a string or a text file). - In myscript.rb: Retrieve input. Set
my_inputto the input. - Set
my_outputto the result ofvarious_string_parsing_voodoo(done to my_input). puts my_output
I intend to actually write the code myself, but if someone could supply me with a skeleton .rb file to send in “Hello World” and get “[World] is pleased by your [hello]” or something equally inane that’d be a great help.
Here are some key pieces:
ARGVis an array containing the arguments you passed when running your script from command line.Fileclass contains several utilies. For example,File.exists?(path)returns true if the path exists, andFile.file?(path)returns true if the path exists and is a file (not a dir).I think this may help you quite a bit.