Skip to content

Instantly share code, notes, and snippets.

@Ball
Ball / Rubish WPF step one.rb
Created August 14, 2009 12:58
Some extentions to WPF classes to make WPF easier in Ironruby
require 'PresentationCore'
require 'PresentationFramework'
include System::Windows
include System::Windows::Controls
class FrameworkElement
def self.create_new( hash )
elem = new()
hash.each_pair do |key, value|
elem.send( "#{key}=".to_sym, value)
@Ball
Ball / bad_example.rb
Created August 15, 2009 16:27
A bad example of WPF and IronRuby
require 'PresentationCore'
require 'PresentationFramework'
Application = System::Windows::Application
HorizontalAlignment = System::Windows::HorizontalAlignment
SizeToContent = System::Windows::SizeToContent
Thickness = System::Windows::Thickness
Window = System::Windows::Window
Button = System::Windows::Controls::Button
@Ball
Ball / xamlbuilder.rb
Created August 15, 2009 17:20
With Xaml
require 'rubygems'
require 'builder'
require 'PresentationCore'
require 'PresentationFramework'
require 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeytoken=b77a5c561934e089'
include System::Windows
StringReader = System::IO::StringReader;
XamlReader = System::Windows::Markup::XamlReader
XmlReader = System::Xml::XmlReader;
@Ball
Ball / xamltools.rb
Created August 22, 2009 16:06
XamlTools
require 'rubygems'
require 'builder'
require 'PresentationCore'
require 'PresentationFramework'
require 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeytoken=b77a5c561934e089'
module XamlTools
include System::Windows
StringReader = System::IO::StringReader;
XamlReader = System::Windows::Markup::XamlReader
@Ball
Ball / bind_example.rb
Created August 22, 2009 16:07
Binding Example
require 'xamltools.rb'
require 'PresentationFramework'
class ViewModel
attr :greeting, true
def initialize(greet)
@greeting = greet
end
end
@Ball
Ball / using_commands.rb
Created August 24, 2009 13:25
Command Example
require 'xamltools.rb'
class MyCommand
include System::Windows::Input::ICommand
def add_CanExecuteChanged(h)
@change_handlers << h
end
def remove_CanExecuteChanged(h)
@change_handlers.remove(h)
end
class DisposableHero
include System::IDisposable
attr :name
def initialize(name = "Jed")
@name = name
end
def do_something_to(other)
puts "#{@name} washes a car for #{other.name}"
end
def do_something
type expression =
| Empty
| Number of int
let expression stream =
match stream with
| [] -> Empty, stream
| h::t -> Number( Int32.Parse(h)), t
let evaluate expr =
match expr with
| Empty -> 0
require 'rubygems'
require 'spec'
require 'spec/autorun'
@watches = []
def watch(matcher, &block)
@watches << Matcher.new(matcher, &block)
end
def do_a_loop(sender, arg)
puts "found a #{arg.change_type} with #{arg.name}"
let rec fibonacci n =
match n with
| 0 -> 0
| 1 -> 1
| _ -> (fibonacci (n-1)) + (fibonacci (n-2))