S
Shangz B.
Hello and warm wishes to everyone who reads my post
I am a newbie to Ruby (That Rhymes!). I am attempting to complete the
"10 Minutes to YOur First Ruby Application" tutorial and I am stuck
about the syntax of the example they are using. I get this error
message:
"You must pass in the path to the file to launch.
Usage: launcher.rb target_file"
The above message is what the last piece of Ruby code in this
application told it to return - - I got that part, but ....
I'm getting frustrated with the code because of the
'placeholders'-- if that what they are -- and my confusion as if I leave
them as is or plug-in the name of the *.rb (launcher.rb) & the file_type
(rb) etc. etc. etc. (Yule Brenner ref) in place of them:
What is app_map? Is app the keyword or is app_map the keyword or do I
stick notepad (my text editor) or ruby in its place. Same goes for
reference to 'select_app,' or 'file_type,' 'file_name,' 'app_map...'
What do I do with those?
The attached file is the 'after' following my attempt at filling in what
I
assume 'file_name' means. The code below is the 'b4'
Any help would be great. I am enthusiastic about learning it, but need a
more thorough explanation of the code snippets they provide in this
tutorial. I am used to reading TSQL and MSSQL.
Thanks in advance, you've been lovely
############################################################
#!/usr/local/bin/ruby
# Example application to demonstrate some basic Ruby features
# This code loads a given file into an associated application
class Launcher
end
launcher = Launcher.new
def initialize( app_map )
@app_map = app_map
end
# Execute the given file using the associate app
def run( file_name )
application = select_app( file_name )
system( "#{application} #{file_name}" )
end
# Given a file, look up the matching application
def select_app( file_name)
ftype = file_type( file_name)
@app_map[ ftype ]
end
# Return the part of the file name string after the last '.'
def file_type( file_name )
File.extname( file_name ).gsub( /^\./, '' ).downcase
end
def help
print "
You must pass in the path to the file to launch.
Usage: #{__FILE__} target_file
"
end
if ARGV.empty?
help
exit
else
app_map= {
'html' => 'firefox',
'rb' => 'gvim',
'jpg' => 'gimp'
}
l = Launcher.new( app_map )
target = ARGV.join( ' ' )
l.run( target )
end
#####################################################
Attachments:
http://www.ruby-forum.com/attachment/6039/RubyForum.txt
I am a newbie to Ruby (That Rhymes!). I am attempting to complete the
"10 Minutes to YOur First Ruby Application" tutorial and I am stuck
about the syntax of the example they are using. I get this error
message:
"You must pass in the path to the file to launch.
Usage: launcher.rb target_file"
The above message is what the last piece of Ruby code in this
application told it to return - - I got that part, but ....
I'm getting frustrated with the code because of the
'placeholders'-- if that what they are -- and my confusion as if I leave
them as is or plug-in the name of the *.rb (launcher.rb) & the file_type
(rb) etc. etc. etc. (Yule Brenner ref) in place of them:
What is app_map? Is app the keyword or is app_map the keyword or do I
stick notepad (my text editor) or ruby in its place. Same goes for
reference to 'select_app,' or 'file_type,' 'file_name,' 'app_map...'
What do I do with those?
The attached file is the 'after' following my attempt at filling in what
I
assume 'file_name' means. The code below is the 'b4'
Any help would be great. I am enthusiastic about learning it, but need a
more thorough explanation of the code snippets they provide in this
tutorial. I am used to reading TSQL and MSSQL.
Thanks in advance, you've been lovely
############################################################
#!/usr/local/bin/ruby
# Example application to demonstrate some basic Ruby features
# This code loads a given file into an associated application
class Launcher
end
launcher = Launcher.new
def initialize( app_map )
@app_map = app_map
end
# Execute the given file using the associate app
def run( file_name )
application = select_app( file_name )
system( "#{application} #{file_name}" )
end
# Given a file, look up the matching application
def select_app( file_name)
ftype = file_type( file_name)
@app_map[ ftype ]
end
# Return the part of the file name string after the last '.'
def file_type( file_name )
File.extname( file_name ).gsub( /^\./, '' ).downcase
end
def help
print "
You must pass in the path to the file to launch.
Usage: #{__FILE__} target_file
"
end
if ARGV.empty?
help
exit
else
app_map= {
'html' => 'firefox',
'rb' => 'gvim',
'jpg' => 'gimp'
}
l = Launcher.new( app_map )
target = ARGV.join( ' ' )
l.run( target )
end
#####################################################
Attachments:
http://www.ruby-forum.com/attachment/6039/RubyForum.txt