Previous Reductive Labs, LLC Next

The Real Ruby: Metaprogrammers Anonymous

def command(hash)
    hash.each do |name, command|
        # Create a method for each passed command
        Object.send(:define_method, name) do |args|
            system("#{command} #{args}")
        end
    end
end

command :echo => "/bin/echo"
command :cat => "/bin/cat"

echo "A string"
cat "/etc/slpsa.conf"

Produces:

A string
# This is the config file for slp sa, empty for now. 
Previous Luke Kanies luke@reductivelabs.com | Index Next