# Events handling

**URL:** <https://www.ruby-forum.com/t/events-handling/177887>\
**Category:** IronRuby\
**Created:** [October 26, 2009, 10:13am UTC](https://www.ruby-forum.com/t/events-handling/177887 "2009-10-26T10:13:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [October 26, 2009, 10:13am UTC](https://www.ruby-forum.com/t/events-handling/177887/1 "2009-10-26T10:13:37Z")

</div>

Hi

I’m trying the following code:

public class ExposingWarrior{  
private readonly int \_id;

```
  public event EventHandler<EventArgs> OnIsExposedChanged;
  public bool IsExposed {get; set; }

  public void Explode(){
      IsExposed = !IsExposed;
      var handler = OnIsExposedChanged;
      if(handler != null){
          handler(this, EventArgs.Empty);
      }
  }

  public bool HasEventSubscriptions{ get { return OnIsExposedChanged 

```

!=  
null; } }  
}

require File.dirname( **FILE** ) + ‘/spec/bin/ClrModels.dll’

class ClrProxy \< ClrModels::ExposingWarrior

def add\_OnIsExposedChanged(handler)  
(@handlers ||= []) \<\< handler  
end

def remove\_OnIsExposedChanged(handler)  
@handlers.delete handler  
end

def to\_s  
“handlers collected: #{(@handlers||[]).size}”  
end  
end

pxy = ClrProxy.new  
ClrModels::ExposedChangedSubscriber.new(pxy)  
puts pxy

###### 

(master)Â» ir event\_test.rb  
handlers collected: 0

* * *

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
GSM: +32.486.787.582  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))
