From: "Shangz B." Date: 2011-03-19T04:35:18+09:00 Subject: Re: "10 Minutes to Your First Ruby Application" Deconstructed! Muchos Gracias Jesus I do appreciate your time. Thank you for responding to my post. Thank you Jesus, :( unfortunately I got syntax errors and no launch of the application. So, wherever the word 'file' appears should I put in its place, "launcher"...? Will I have to substitute 'rb' wherever file_type() appears? When I took out the "launcher=Launcher.new" it gave syntax errors as with placing the end after everything. Excuse me for being thick. I really would like to understand. And just so I don't bug you too much is there any other place I can get an explanation of this particular or a breakdown of this tutorial line-by-line? I attempted the "Ruby Syntax" link, but I need a reference as I go through this tutorial. Thanks again:) ######################################################################## "Jesús Gabriel y Galán" wrote in post #988096: > On Fri, Mar 18, 2011 at 7:06 AM, Shangz B. wrote: >> >> reference to 'select_app,' or 'file_type,' 'file_name,' 'app_map...' >> Thanks in advance, you've been lovely :) >> >> end >> end >> help >> l.run( target ) >> end >> >> >> ##################################################### >> >> Attachments: >> http://www.ruby-forum.com/attachment/6039/RubyForum.txt > > I see some strange things: > > First of all: initialize, run, select_launcher and file_type > definitions should be inside class Launcher ... end, because they > should be instance methods of class Launcher. > You can remove the launcher = Launcher.new, since you are not using it. > After that, I think the application should work, if you call it like: > > ruby launcher.rb test.html > > it should launch firefox with test.html as a parameter. Also, the > parameter name launcher in the methods run and select_launcher is > confusing, since you are not passing the launcher, but the target. So, > this is how it would look like (I change other minor things): > > #!/usr/bin/env ruby > > class Launcher > def initialize(launcher_map) > @app_map = launcher_map > end > > # Execute the given file using the associate app > def run(file) > application = select_launcher(file) > system ("#{application} #{file}") > end > > # Given a file, look up the matching application > def select_launcher(file) > ftype = file_type(file) > @app_map [ftype] > end > > # Return the part of the file name string after the last '.' > def file_type(file) > File.extname(file)[1..-1].downcase > end > end > > def help > puts "You must pass in the path to the file to launch." > puts > puts "Usage: #{__FILE__} target_file" > end > > if ARGV.empty? > help > exit > end > > app_map= {'html' => 'firefox', 'rb' => 'notepad', 'jpg' => 'gimp'} > l = Launcher.new( app_map) > target = ARGV.join( ' ' ) > l.run( target ) > > Jesus. -- Posted via http://www.ruby-forum.com/.