Question: I need to change a property on a class a few minutes after it it initialized. I attempted to use `sleep` inside a function but it delayed execution of everything:

```
active = true

def deactivate
  sleep 120
  puts 'deactivate'
  active = false
end

deactivate
puts active

```

What I was hoping would happen is `true` would log out first then two minutes later `deactivate` would log. However, what happens is `deactivate` then `false` log out after two minutes.

In JavaScript I would do something like:

```
var active = true;
setTimeout(function(){
  console.log('deactivate');
  active = false;
},120000);
console.log(active);

```

Answer: 
Looks overkill for this task, but you can use [delayed\_job](https://github.com/tobi/delayed_job) to run a task at a future time asynchronously.

```
  def deactivate
     puts 'deactivate'
     active = false
  end

  active = true
  handle_asynchronously :deactivate, :run_at => Proc.new { 2.minutes.from_now }

```
Well, it seems to me (When I try this code) the active and deactivate is out of order. So why not do this?:

```
   active = true

   def deactivate
     sleep 120
     puts 'deactivate'
     active = false
   end

   puts active
   deactivate

```

It works perfectly.