mirror of
https://github.com/rubyjs/therubyrhino
synced 2023-03-27 23:21:34 -04:00
35 lines
No EOL
745 B
Ruby
35 lines
No EOL
745 B
Ruby
|
|
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 |