Changeset 3044

Show
Ignore:
Timestamp:
12/11/07 16:10:45 (6 years ago)
Author:
nshuyo
Message:

lang/javascript/jsruby: added method_missing support

Location:
lang/javascript/jsruby/trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/jsruby/trunk/src/builtinobjects.js

    r2989 r3044  
    1010  return c; 
    1111} 
     12RubyEngine.RubyObject.call = function(self, name, args, block){ 
     13  var clz = self.clz; 
     14  var method; 
     15  while( !(method=clz.methods[name]) ) if ( !(clz=clz.superclz) ) break; 
     16  if (method) { 
     17    return method.apply(this, [self, args, block]); 
     18  } else if (name!="method_missing") { 
     19    var newarg = [new RubyEngine.RubyObject.String(node.name)].concat(node.args); 
     20    var ret = RubyEngine.RubyObject.call.apply(this, [self, "method_missing", newarg, node.block]); 
     21    if (ret!=undefined) return ret; 
     22    return new RubyEngine.RubyObject.NameError("undefined local variable or method `"+name+"' for "+self.clz.toString(), name); 
     23  } 
     24  return undefined; 
     25}; 
    1226 
    1327 
    1428RubyEngine.RubyObject.Object = function(){ this.clz = RubyEngine.RubyObject.Object; } 
    1529RubyEngine.RubyObject.Object.prototype.toValue = function(){ return this; } // to Javascript value(instance) 
    16 RubyEngine.RubyObject.Object.prototype.call = function(ruby, name, args, block){ 
    17   var clz = this.clz; 
    18   var method; 
    19   while( !(method=clz.methods[name]) ) if ( !(clz=clz.superclz) ) break; 
    20   if (method) { 
    21     return method.apply(ruby, [this, args, block]); 
    22   } else { 
    23   } 
    24 }; 
    2530 
    2631 
  • lang/javascript/jsruby/trunk/src/interpreter.js

    r2991 r3044  
    155155    obj = this.run(node.target); 
    156156  } 
    157   var method = obj.clz.methods[node.name]; 
    158   if (method) { 
    159     return method.apply(this, [obj, node.args, node.block]); 
    160   } else { 
    161     alert("undefined method :" + obj.toSource() + "." + node.toSource()); 
    162   } 
     157  return RubyEngine.RubyObject.call.apply(this, [obj, node.name, node.args, node.block]); 
    163158} 
    164159