Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Dynamic function calls

Reply
Thread Tools

Dynamic function calls

 
 
Tomas Fischer
Guest
Posts: n/a
 
      02-14-2007
Hi,

I want to write an installer, which checks, if sth. is present on the
target system and if not, the installer will install it. For example,
the installer checks if zip is installed.

So I have tons of check functions and corresponding install funtions:

def check_zip
...
return true / false
end

def install_zip
...
system(apt-get install zip)
end

My idea is to use an array, which contains the result of the checking
process
array= [zip, ...] means, that we have to install zip. Is it possible to
"connect" it
to the corresponding install function?

for each element in array
call install_ array[index]
end


Thanks.

Best regards,

Tomas

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Marcello Barnaba
Guest
Posts: n/a
 
      02-14-2007
--nextPart1672480.qH981OrMCd
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

On Wednesday 14 February 2007 14:46, Tomas Fischer wrote:
> Hi,
>
> I want to write an installer, which checks, if sth. is present on the
> target system and if not, the installer will install it. For example,
> the installer checks if zip is installed.
>
> So I have tons of check functions and corresponding install funtions:
>
> def check_zip
> ...
> return true / false
> end
>
> def install_zip
> ...
> system(apt-get install zip)
> end


why don't you pass a parameter to a single "check" method?

def check(program)
@directories ||=3D ENV['PATH'].split(File:ATH_SEPARATOR)
@directories.find { |dir| File.executable?(File.join(dir, program)) }
end

def install(program, package =3D nil)
unless check(program)
package ||=3D program
system "apt-get install #{package}"
end
end

%w(zip unzip rar unrar).each { |program| install program }

obivously with some software such as unrar-nonfree you should pass also the=
=20
package name to the "install" method.

HTH
=2D-=20
pub 1024D/8D2787EF 723C 7CA3 3C19 2ACE 6E20 9CC1 9956 EB3C 8D27 87EF

--nextPart1672480.qH981OrMCd
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQBF0xnsmVbrPI0nh+8RAvkRAKCFadmFXM9/gljXFACjbDHzAinjZwCgwrHi
A3tkuYuZRJ6ZWY5iMjOHrS0=
=G872
-----END PGP SIGNATURE-----

--nextPart1672480.qH981OrMCd--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'Dynamic' function calls BartC C Programming 26 12-31-2012 10:59 AM
This function has an onClick event that calls a function that calls This function Bob Javascript 5 10-24-2006 04:11 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
MoVoIP - FREE MOBILE Inetrnet Phone Calls - FREE Internet Phone Calls ubifone VOIP 0 07-29-2005 04:31 PM
Sequence of constructor calls and destructor calls. Honne Gowda A C++ 2 10-31-2003 09:31 AM



Advertisments