Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created June 10, 2010 04:48
Show Gist options
  • Save mattpodwysocki/432562 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/432562 to your computer and use it in GitHub Desktop.
require 'System.CoreEx, Version=1.0.2521.104, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
require 'System.Interactive, Version=1.0.2521.104, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
require 'System.Reactive, Version=1.0.2521.104, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
require 'System.Windows.Forms'
include System
include System::Collections::Generic
include System::Linq
include System::Windows::Forms
class TestForm < Form
def initialize()
self.Text = 'Hello IronRuby'
end
end
form = TestForm.new
clickObservable = Observable.method(:from_event).of(EventArgs).call(form, 'Click')
clickObserver = Observer.method(:create).of(IEvent[EventArgs]).call(
lambda {|on_next| MessageBox::show('clicked') },
lambda { |err| puts err.to_s },
lambda { puts 'completed' })
clickSubcription = clickObservable.subscribe(clickObserver)
Application.run(form)
@panesofglass
Copy link

With IronRuby 1.1, it looks like you could do something like

using_clr_extensions System::Linq
using_clr_extensions System::Observable

# Snipped form and includes ...
clickObservable = form.from_event('Click')
clickSubscription = clickObservable.subscribe(
  lambda { |on_next| MessageBox::show('clicked') },
  lambda { |err| puts err.to_s },
  lambda { puts 'completed' })

Application.run(form)

I haven't tried this, but it seems plausible.

@panesofglass
Copy link

Well nevermind! Looks like you've already done it! :) Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment