| Previous | Reductive Labs, LLC | Next |
The Real Ruby: Metaprogrammers Anonymousdef 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:
|
| Previous | Luke Kanies luke@reductivelabs.com | Index | Next |