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: 
Using @ihaztehcodez's suggestion of a Thread I came up with the simple solution I was looking for:

```
Thread.new do
  sleep 120
  puts 'deactivate'
  active = false
end

```

His warning about persistence doesn't worry me in this case since I am using it for non-critical notifications. If the execution was critical then storing something in a database like @spickermann said or using a library like @k-m-rakibul-islam suggested would be the better solution.
Why not just store the time until it is active? 

Then there is no need to block, callback or run anything async at all. When you store `active_until` in a datetime column in a database model, then it allows you keep track of changes and keep the current `active` status even over several different requests to the app:

```
def active
  active_until.blank? || Time.current < active_until
end

def deactivate
  update_columns(active_until: 2.minutes.since)
end

```