--nextPart1672480.qH981OrMCd
Content-Type: text/plain;
  charsettf-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 ||= ENV['PATH'].split(File::PATH_SEPARATOR)
  @directories.find { |dir| File.executable?(File.join(dir, program)) }
end

def install(program, package = nil)
  unless check(program)
    package ||= 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 
package name to the "install" method.

HTH
-- 
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
A3tkuYuZRJ6ZWY5iMjOHrS072
-----END PGP SIGNATURE-----

--nextPart1672480.qH981OrMCd--