Class: Rhino::RubyObject::Prototype

Inherits:
J::ScriptableObject
  • Object
show all
Defined in:
lib/rhino/ruby_object.rb

Constant Summary collapse

Generic =
new

Instance Method Summary collapse

Instance Method Details

#get(name, start) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rhino/ruby_object.rb', line 45

def get(name, start)
  robject = To.ruby(start)
  if name == "toString"
    return RubyFunction.new(lambda { "[Ruby #{robject.class.name}]"})
  end
  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)
    else
      RubyFunction.new(method)
    end
  else
    super(name, start)
  end
end

#has(name, start) ⇒ Object



63
64
65
66
# File 'lib/rhino/ruby_object.rb', line 63

def has(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