Skip to content

Instantly share code, notes, and snippets.

<script language="ruby" src="application.rb"></script>
<script language="javascript" src="gestalt.js" />
<div id="message"></div>
<script language="ruby">
document.message.innerHTML = "Hello, World!"
</script>
load_assembly "System.Core"
#=> true
System::Linq::Enumerable.First([1,2,3])
#=> 1
System::Linq::Enumerable.ElementAt([1,2,3,4,5], 2)
#=> 3
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);
}
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
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
// c.dll
public class C {
public void Foo<T>(T x) { Console.WriteLine(typeof(T)); }
}
require 'c'
C.new.foo(1)
# System.Int32
C.new.foo("x")
# IronRuby.Builtins.MutableString
C.new.foo(1.0)
# System.Double
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
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"