1
0
Fork 0
mirror of https://github.com/rubyjs/therubyrhino synced 2023-03-27 23:21:34 -04:00
therubyrhino/lib/rhino/ruby_object.rb

35 lines
745 B
Ruby
Raw Normal View History

module Rhino
class RubyObject < J::ScriptableObject
include J::Wrapper
def initialize(object)
super()
@ruby = object
end
def unwrap
@ruby
end
def getClassName()
@ruby.class.name
end
def getPrototype()
@prototype ||= J::NativeObject.new.tap do |p|
p.put("toString", p, Function.new {to_s})
for name in @ruby.public_methods(false).reject {|m| m == 'initialize'}
method = @ruby.method(name)
p.put(name.gsub(/_(\w)/) {$1.upcase}, p, Function.new(method) {})
end
end
end
def to_s
"[Native #{@ruby.class.name}]"
end
alias_method :prototype, :getPrototype
end
end