Dynamic function calls

T

Tomas Fischer

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
 
M

Marcello Barnaba

--nextPart1672480.qH981OrMCd
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

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::pATH_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--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top