On Mon, 16 Oct 2006, Andre Nathan wrote: > Hi > > I was quite bored this morning and the coffee machine went into its 30 > minute clean cycle, so I came up with this... > > $ cat .irbrc > Dir["{,/usr,/usr/local}/bin/*"].each do |bin| > Object.instance_eval do > define_method(File.basename(bin)) do |*args| > args.map! { |arg| arg.to_s } > system bin, *args > end > end > end cool idea. i tweaked it to do lazy method definition: harp:~ > cat .irbrc module Kernel PATH = ENV['PATH'].split File::PATH_SEPARATOR end class Object def self.binattr bin bin = bin.to_s m = File.basename bin unless respond_to?(m) define_method(m){|*a| system bin, *a.map{|s| s.to_s}} end end def which bin b = bin.to_s if b =~ %r|^#{ File::SEPARATOR }| b else dir = PATH.detect{|d| test(?e, File.join(d,b))} dir ? File.join(dir,b) : nil end end alias_method "__mm__", "method_missing" def method_missing m, *a, &b bin = which m if bin Object.binattr(bin) and send(m,*a,&b) else __mm__(m,*a,&b) end end end fun stuff! -a -- my religion is very simple. my religion is kindness. -- the dalai lama