
-----------------------------------
shangbaby
Sat Mar 19, 2011 1:51 pm

&quot;10 Minutes to Writing Your First Ruby Application&quot;
-----------------------------------
I found this tutorial at devx.com
 :D I would appreciate a line-by-line explanation of how to:

1) make this code work as expected on my machine
2) what am I supposed to plug-in to get my file's application to execute
3) Am I supposed to plug-in the file wherever 'file_name' appears in the code.
4) What does app_map mean? Is '_map' a function of Ruby?
5) I will appreciate any help given. Thank You for your time.


#!/usr/local/bin/ruby   'notepad', 'rb' => 'ruby'} defines the map we are providing the classes, mapping file extensions to an appropriate application name. You can then call the run method on the newly created launcher object, passing in a file you want to open. The run method calls some of the other methods in the class to extract the file extension from the name we pass in, and then look that extension up in the app_map to find the application corresponding to that extension. It then uses the Ruby system function to execute a command such as 'notepad test.txt', opening the file in the application.


Insectoid is right, you should probably start with a basic Ruby tutorial. Try going through the Ruby Quick Start here:
http://www.ruby-lang.org/en/documentation/quickstart/

-----------------------------------
tomasdore
Wed Apr 27, 2011 2:04 pm

Re: &quot;10 Minutes to Writing Your First Ruby Application&quot;
-----------------------------------
Hi, I believe that this is the article that you are referring to: 
http://www.devx.com/RubySpecialReport/Article/34502/0/page/1

1) They have a note on the side of the page, in the 'sidebar', which gives info for Windows users, like yourself:
http://www.devx.com/RubySpecialReport/Article/34502/1763?supportItem=1
That should work if you used that installer (that they mention).

2) When you run the program from the command line, you type in something similar to what they have put at the end of the second page:
ruby launcher.rb launcher.rb
You can see this at the end of page 2, which is at http://www.devx.com/RubySpecialReport/Article/34502/0/page/2
That is a bit of a confusing one that they have chosen. If you wanted to open a file that was called index.html, assuming it's in the same folder as your Ruby file (which is your launcher.rb file), then you would type
ruby launcher.rb index.html
This will open in Firefox, so you will need to have Firefox installed.

3) No. That's just a variable name in the code, just leave it as is. You plug in the file name where I plugged in index.html in the example just above in part 2).

4) app_map is a hash, not a function that is built in to Ruby, just something they've created during the tutorial, to store information in. They made up this name for it probably because the information it stores is which application (app) to use to open each type of file, so in that sense the information they are storing in the app_map hash is a mapping between the file types (based on their endings) and the corresponding program that the computer is being told to run to open that file type.
It's listed in the code on page 2, at http://www.devx.com/RubySpecialReport/Article/34502/0/page/2
If you want to be able to open more file types, add them to the app_map hash in the code.
For example you could add 
'txt' => 'notepad', 
as one of the lines, perhaps on a new line just after the firefox line would be a good place as then the end comma will be useful to you. Then you could change the example above to launch a txt file instead of a html file; and so on, if you add other file types to the app_map hash.

Maybe see if this gets you further, or post back and let me know if it isn't clear.
Tom.
