Skip to content

Instantly share code, notes, and snippets.

# accessing named child elements
### normal
w.find_name("msg").text = "Hello"
### wpf.rb
w.msg.text = "Hello"
# showing, hiding, and collapsing elements
### normal
include System::Windows
e.visibility = Visibility.hidden
# make sure we put "Lib" on the path -- this contains only
# libs required to load unittest ...
import sys
sys.path.append("Lib")
# stop the SL loading animation by setting the rootvisual
from System.Windows import Application
from System.Windows.Controls import UserControl
Application.Current.RootVisual = UserControl()
require 'benchmark'
Benchmark.bm { |x| x.report { require 'rubygems' } }
#
# user system total real
# eager transformation
# 1.622410 0.031200 1.653611 ( 1.581316)
# lazy transformation
# 1.170008 0.031200 1.201208 ( 1.099220)
#
System::Byte.instance_methods(false)
#=> ["-", "%", "&", "*", "**", "/", "-@", "[]", "^", "|", "~", "+", "<", "<<", "<=", "<=>", "==", ">", ">=", ">>", "abs", "div", "divmod", "modulo", "quo", "to_f", "to_s", "zero?", "size", 'compare_to', 'equals', 'get_hash_code', 'to_string', 'get_type_code']
l = System::Byte.instance_methods(false).last
#=> 'get_type_code'
l.ruby_name
#=> "get_type_code"
l.clr_name
#=> "GetTypeCode"
class System::Decimal
instance_methods(false).each do |name|
mangled = '__' + name
alias_method(mangled, name)
private mangled
define_method(name) do |*args|
puts "method called: #{name}"
send mangled, *args
end
end
require 'c'
C.new.foo(1)
# System.Int32
C.new.foo("x")
# IronRuby.Builtins.MutableString
C.new.foo(1.0)
# System.Double
// c.dll
public class C {
public void Foo<T>(T x) { Console.WriteLine(typeof(T)); }
}
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario Outline: Add two numbers
Given I have entered <input_1> into the calculator
And I have entered <input_2> into the calculator
When I press add
Then the result should be <output> on the screen
require 'spec/expectations'
require 'Calculator' # Calculator.dll
Before do
@calc = Demo::Calculator.new # A .NET class in Calculator.dll
end
Given "I have entered $n into the calculator" do |n|
@calc.push n.to_i
end
using System;
using System.Collections.Generic;
namespace Demo {
public class Calculator {
private List<int>args = new List<int>();
public void Push(int n) {
args.Add(n);
}