Permalink
Browse files

Extract ConsoleInterp#expose into Tcl::Interp

git-svn-id: svn://rubyforge.org/var/svn/tcl/trunk@11 017b7ecb-b1d0-4998-98d6-e9014aaf4887
  • Loading branch information...
sstephenson committed Dec 7, 2007
1 parent 3f92d94 commit a70040bf7054a9256c77e3d738d22673b980d5c3
Showing with 22 additions and 6 deletions.
  1. +5 −1 lib/tcl/interp.rb
  2. +0 −5 script/console
  3. +17 −0 test/interp_receive_test.rb
View
@@ -17,7 +17,11 @@ def interp
def interp_receive(method, *args)
send("tcl_#{method}", *args)
end
-
+
+ def expose(name)
+ _!(:interp, :alias, nil, name, nil, :interp_send, name)
+ end
+
def proc(name)
Tcl::Proc.new(self, name)
end
View
@@ -11,11 +11,6 @@ class ConsoleInterp < Tcl::Interp
def tcl_ruby_eval(script)
Kernel.eval(script)
end
-
- protected
- def expose(name)
- _!(:interp, :alias, nil, name, nil, :interp_send, name)
- end
end
filename = ARGV.shift || File.join(File.dirname(__FILE__), *%w".. .state.dat")
@@ -28,6 +28,17 @@ def interp_receive(method, *args)
end
end
+class InterpWithExposedMethods < Tcl::Interp
+ def initialize
+ super
+ expose :hello
+ end
+
+ def tcl_hello(who)
+ "hello, #{who}"
+ end
+end
+
class InterpReceiveTest < Test::Unit::TestCase
def setup
@interp = InterpWithDefaultReceiveMethod.new
@@ -70,5 +81,11 @@ def test_interp_send_with_custom_interp_receive_method
assert_equal "foo", @interp.eval("interp_send foo")
assert_equal "foo bar", @interp.eval("interp_send foo bar")
end
+
+ def test_interp_expose
+ @interp = InterpWithExposedMethods.new
+ assert_equal "hello, Sam", @interp.eval("interp_send hello Sam")
+ assert_equal "hello, Sam", @interp.eval("hello Sam")
+ end
end

0 comments on commit a70040b

Please sign in to comment.