internal Method(object recv, string id) : base(Ruby.Runtime.Init.rb_cMethod) { this.id = id; this.recv = recv; this.body = Eval.FindPrivateMethod(recv, null, id, out rklass); }
internal Method(object recv, string id, string oid, Class rklass, RubyMethod body) : this(recv, id) { this.oid = oid; this.rklass = rklass; this.body = body; }
internal Method(object recv, string id, string oid, Class rklass, Class oklass, RubyMethod body, bool unbound) : this(recv, id) { if (unbound) this.my_class = Ruby.Runtime.Init.rb_cUnboundMethod; this.oid = oid; this.rklass = rklass; this.oklass = oklass; this.body = body; }
internal override bool get_method(string methodId, out RubyMethod method, out Class klass) { if (_methods.TryGetValue(methodId, out method)) { klass = this; return true; } if (null != (method = FindCLRMethod(methodId, clrtype))) { klass = this; this._methods[methodId] = method; return true; } if (super != null && super.get_method(methodId, out method, out klass)) return true; klass = null; return false; }
internal MethodAlias(RubyMethod orig): base(orig.body, orig.arity, orig.access, orig.definingClass) { }
internal void redefine_visibility(Frame caller, string name, Access noex)//author: Brian, status: done { RubyMethod method; Class origin; if (!get_method(name, out method, out origin)) { if (!((_type == Type.Module) && (Ruby.Runtime.Init.rb_cObject.get_method(name, out method, out origin)))) { // cannot redefine visibility for nonexistant method throw new NameError("undefined method '" + name + "' for " + name).raise(caller); } } if (origin == this) method.access = noex; else _methods[name] = new RubyMethod(new CallSuperMethodBody(this, name), method.arity, noex, this); }
// BBTAG: corresponds to rb_add_method: complete implementation of method definition, // including invocation tests internal void add_method(string name, MethodBody body, int arity, Access access, Frame caller)//author: Brian, status: done { Debug.Assert(_methods != null); if (Eval.rb_safe_level() >= 4 && (this == Ruby.Runtime.Init.rb_cObject || !Tainted)) throw new SecurityError("Insecure: can't define method").raise(caller); if ((_type != Type.Singleton) && (name.Equals("initialize") || name.Equals("initialize_copy"))) access = Access.Private; else if ((_type == Type.Singleton) && name.Equals("allocate")) { Errors.rb_warn((System.String.Format(CultureInfo.InvariantCulture, "defining {0}.allocate is deprecated; use define_alloc_func()", ((Class)attached)._name))); name = "allocator"; } _methods[name] = new RubyMethod(body, arity, access, this); if (!name.Equals("allocator") && Eval.RubyRunning) { if (_type == Type.Singleton) Eval.CallPrivate(attached, caller, "singleton_method_added", null, new Symbol(name)); else Eval.CallPrivate(this, caller, "method_added", null, new Symbol(name)); } }
internal virtual bool get_method(string methodId, out RubyMethod method, out Class klass) { if (_methods.TryGetValue(methodId, out method)) { klass = this; return true; } Class superKlass = super; if (superKlass != null) { // BBTAG: calling new for a subclass of a CLRClass is a special case if (this._type == Type.Singleton && superKlass is Interop.CLRClass && !(this is Interop.CLRClass) && methodId == "new") { klass = this; method = new RubyMethod(Ruby.Methods.rb_class_new_instance.singleton, -1, Access.Public, this); return true; } if (superKlass.get_method(methodId, out method, out klass)) return true; } klass = null; return false; }
internal bool get_method(string methodId, out RubyMethod method) { Class klass; return get_method(methodId, out method, out klass); }