Skip to content

Instantly share code, notes, and snippets.

@jschementi
Created July 19, 2010 08:25
Show Gist options
  • Save jschementi/481156 to your computer and use it in GitHub Desktop.
Save jschementi/481156 to your computer and use it in GitHub Desktop.
MIX10, Part 2.2 & 3
foo_module = IronRuby.require 'foo'
foo_module.Foo.new.bar
class Foo(object):
def bar(self):
print 'Look ma, white-space-sensitivity!'
var runtime = ScriptRuntime.CreateFromConfiguration();
var engine = runtime.GetEngine("IronPython");
dynamic scope = engine.CreateScope();
scope.page = this;
engine.Execute("page.Message.Text = 'Hello from Python!'", scope);
describe '.NET Stack instantiation' do
it 'can create an empty stack' do
stack = Stack.new
stack.should.be_kind_of Stack
stack.count.should == 0
end
it 'can create a stack from an array' do
stack = Stack.new [1,2,3]
stack.should.be_kind_of Stack
stack.count.should == 3
end
end
require 'IronPython'
require 'Microsoft.Scripting'
include Microsoft::Scripting::Hosting
include IronPython::Hosting
python = Python.create_engine
scope = python.create_scope
python.execute "
class Foo(object):
def bar(self):
print 'Look ma, white-space-sensitivity!'
", scope
python.execute "Foo().bar()", scope
<script type="text/ruby" src="foo.rb"></script>
def describe string
puts string
yield
end
def it string
puts &quot; #{string} &quot;
yield
end
class Object
def should
PositiveAssertion.new(self)
end
end
class PositiveAssertion
def initialize lhs
@lhs = lhs
end
def == rhs
print @lhs == rhs ? '.' : 'F'
end
def be_kind_of type
self.class.new(@lhs.class) == type
end
end
class DotNetStackInstantiation < Test::Unit::TestCase
def test_creating_empty_stack
stack = Stack.new
assert(stack.kind_of? Stack)
assert(stack.count == 0)
end
def test_creating_stack_from_array
stack = Stack.new [1,2,3]
assert(stack.kind_of? Stack)
assert(stack.count == 3)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment