From: Robert Klemme Date: 2012-06-27T18:18:47+09:00 Subject: Re: how about adding method hook On Wed, Jun 27, 2012 at 10:12 AM, salamond wrote: > Hi, guys. > > I want An agent on machine, so that it can fake user actions. > > class Agent >   def initialize(user, dir) >     @user = user >     @dir = dir >   end >   def mkdir(dir) >     bak = Process.euid >     `mkdir` >     Process.euid = bak >   end >   def create_file(file, content) >     bak = Process.euid >     `echo #{content} > #{file}` >     Process.euid = bak >   end > end > > My problem is, I have a very long list of actions, like mv, touch, mkdir, > rm, etc. > I don't want to add save and restore euid for all methods. Btw, your code is not safe as it does not restore on exception. > Any one been here before? Could be that AspectR is for you. I also once created code to insert methods before and after a method invocation but I can't seem to find it in the archives. A simple solution could look like this https://gist.github.com/3002732 Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/