Permalink
Browse files

Interop API: create ruby modules

  • Loading branch information...
1 parent 61f4c9f commit 257b3be9df34d8ca0c502dfaed316ad489637c96 @txus committed Jan 27, 2012
Showing with 22 additions and 0 deletions.
  1. +6 −0 lib/noscript/runtime.rb
  2. +16 −0 test/interop_test.rb
View
@@ -102,6 +102,12 @@ def noscript_def(name, &block)
class Class
noscript_alias [:new]
+end
+
+class Module
+ noscript_def 'create' do |implementation|
+ Module.new(&implementation)
+ end
noscript_def 'def' do |name, implementation|
define_method(name, &implementation)
end
View
@@ -47,4 +47,20 @@ def test_extend_ruby_module
assert_respond_to foo, :mixin_method
assert_equal 1234, foo.mixin_method
end
+
+ def test_create_ruby_module
+ mod = compile(<<-CODE)
+ Ruby.Module.create(->
+ @def('answer', ->
+ 42
+ end)
+ end)
+ CODE
+
+ foo = Foo.new
+ foo.extend(mod)
+
+ assert_respond_to foo, :answer
+ assert_equal 42, foo.answer
+ end
end

0 comments on commit 257b3be

Please sign in to comment.