diff --git a/lib/rhino/ruby_function.rb b/lib/rhino/ruby_function.rb index 3be1147..49d7f68 100644 --- a/lib/rhino/ruby_function.rb +++ b/lib/rhino/ruby_function.rb @@ -8,7 +8,7 @@ module Rhino end def call(cxt, scope, this, args) - To.javascript @callable.call(*args.map {|a| To.ruby(a)}) + To.javascript @callable.call(*Array(args).map {|a| To.ruby(a)}) end end end \ No newline at end of file diff --git a/lib/rhino/ruby_object.rb b/lib/rhino/ruby_object.rb index 9483325..6767f61 100644 --- a/lib/rhino/ruby_object.rb +++ b/lib/rhino/ruby_object.rb @@ -47,8 +47,8 @@ module Rhino if name == "toString" return RubyFunction.new(lambda { "[Ruby #{robject.class.name}]"}) end - rb_name = name.gsub(/([a-z])([A-Z])/) {"#{$1}_#{$2.downcase}"} - if (robject.public_methods(false).include?(rb_name)) + rb_name = name.gsub(/([a-z])([A-Z])/) {"#{$1}_#{$2.downcase}"}.to_sym + if (robject.public_methods(false).collect(&:to_sym).include?(rb_name)) method = robject.method(rb_name) if method.arity == 0 To.javascript(method.call) @@ -61,12 +61,11 @@ module Rhino end def has(name, start) - rb_name = name.gsub(/([a-z])([A-Z])/) {"#{$1}_#{$2.downcase}"} - To.ruby(start).public_methods(false).respond_to?(rb_name) ? true : super(name,start) + rb_name = name.gsub(/([a-z])([A-Z])/) {"#{$1}_#{$2.downcase}"}.to_sym + To.ruby(start).public_methods(false).collect(&:to_sym).include?(rb_name) ? true : super(name,start) end Generic = new - end end end diff --git a/spec/rhino/context_spec.rb b/spec/rhino/context_spec.rb index 5d73957..0f6f406 100644 --- a/spec/rhino/context_spec.rb +++ b/spec/rhino/context_spec.rb @@ -25,6 +25,15 @@ describe Rhino::Context do end end + it "allows you to scope the context to an object" do + class MyScope + def foo; proc { 'bar' }; end + end + Context.open(:with => MyScope.new) do |ctx| + ctx.eval("foo()").should == 'bar' + end + end + it "allows you to seal the standard objects so that they cannot be modified" do Context.open(:sealed => true) do |cxt| lambda {