Sha256: bf418c0faeddb91eaca3dcdf98d6ba3f69b323fdbd52aa5c2e3d76d797719908
Contents?: true
Size: 1.29 KB
Versions: 13
Compression:
Stored size: 1.29 KB
Contents
class Method attr_reader :owner, :receiver, :name def initialize(receiver, method, name) @receiver = receiver @owner = receiver.class @name = name @method = method end def arity @method.arity end def parameters `#{@method}.$$parameters` end def call(*args, &block) %x{ #@method.$$p = block; return #@method.apply(#@receiver, args); } end alias [] call def unbind UnboundMethod.new(@owner, @method, @name) end def to_proc %x{ var proc = function () { return self.$call.apply(self, $slice.call(arguments)); }; proc.$$unbound = #@method; proc.$$is_lambda = true; return proc; } end def inspect "#<Method: #{@receiver.class}##@name>" end end class UnboundMethod attr_reader :owner, :name def initialize(owner, method, name) @owner = owner @method = method @name = name end def arity @method.arity end def parameters `#{@method}.$$parameters` end def bind(object) # TODO: re-enable when Module#< is fixed # unless object.class <= @owner # raise TypeError, "can't bind singleton method to a different class" # end Method.new(object, @method, @name) end def inspect "#<UnboundMethod: #{@owner.name}##@name>" end end
Version data entries
13 entries across 13 versions & 1 rubygems