class Method < Object # Returns a `Proc` object corresponding to this method. def to_proc: () -> Proc # Invokes the *meth* with the specified arguments, returning the method’s # return value. # # ```ruby # m = 12.method("+") # m.call(3) #=> 15 # m.call(20) #=> 32 # ``` def call: (*untyped args) -> untyped # Returns a proc that is the composition of this method and the given *g* # . The returned proc takes a variable number of arguments, calls *g* with # them then calls this method with the result. # # ```ruby # def f(x) # x * x # end # # f = self.method(:f) # g = proc {|x| x + x } # p (f << g).call(2) #=> 16 # ``` def <<: (Proc g) -> Proc # Invokes the method with `obj` as the parameter like # [call](Method.downloaded.ruby_doc#method-i-call). This allows a method # object to be the target of a `when` clause in a case statement. # # ```ruby # require 'prime' # # case 1373 # when Prime.method(:prime?) # # ... # end # ``` alias === call # Returns a proc that is the composition of this method and the given *g* # . The returned proc takes a variable number of arguments, calls *g* with # them then calls this method with the result. # # ```ruby # def f(x) # x * x # end # # f = self.method(:f) # g = proc {|x| x + x } # p (f >> g).call(2) #=> 8 # ``` def >>: (Proc g) -> Proc # Invokes the *meth* with the specified arguments, returning the method’s # return value. # # ```ruby # m = 12.method("+") # m.call(3) #=> 15 # m.call(20) #=> 32 # ``` alias [] call # Returns an indication of the number of arguments accepted by a method. # Returns a nonnegative integer for methods that take a fixed number of # arguments. For Ruby methods that take a variable number of arguments, # returns -n-1, where n is the number of required arguments. Keyword # arguments will be considered as a single additional argument, that # argument being mandatory if any keyword argument is mandatory. For # methods written in C, returns -1 if the call takes a variable number of # arguments. # # class C # def one; end # def two(a); end # def three(*a); end # def four(a, b); end # def five(a, b, *c); end # def six(a, b, *c, &d); end # def seven(a, b, x:0); end # def eight(x:, y:); end # def nine(x:, y:, **z); end # def ten(*a, x:, y:); end # end # c = C.new # c.method(:one).arity #=> 0 # c.method(:two).arity #=> 1 # c.method(:three).arity #=> -1 # c.method(:four).arity #=> 2 # c.method(:five).arity #=> -3 # c.method(:six).arity #=> -3 # c.method(:seven).arity #=> -3 # c.method(:eight).arity #=> 1 # c.method(:nine).arity #=> 1 # c.method(:ten).arity #=> -2 # # "cat".method(:size).arity #=> 0 # "cat".method(:replace).arity #=> 1 # "cat".method(:squeeze).arity #=> -1 # "cat".method(:count).arity #=> -1 def arity: () -> Integer # Returns a clone of this method. # # ```ruby # class A # def foo # return "bar" # end # end # # m = A.new.method(:foo) # m.call # => "bar" # n = m.clone.call # => "bar" # ``` def clone: () -> Method def curry: (?Integer arity) -> Proc # Returns the name of the method. def name: () -> Symbol # Returns the original name of the method. # # ```ruby # class C # def foo; end # alias bar foo # end # C.instance_method(:bar).original_name # => :foo # ``` def original_name: () -> Symbol # Returns the class or module that defines the method. See also receiver. # # ```ruby # (1..3).method(:map).owner #=> Enumerable # ``` def owner: () -> (Class | Module) # Returns the parameter information of this method. # # ```ruby # def foo(bar); end # method(:foo).parameters #=> [[:req, :bar]] # # def foo(bar, baz, bat, &blk); end # method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:req, :bat], [:block, :blk]] # # def foo(bar, *args); end # method(:foo).parameters #=> [[:req, :bar], [:rest, :args]] # # def foo(bar, baz, *args, &blk); end # method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]] # ``` def parameters: () -> ::Array[ [:req | :opt | :rest | :keyreq | :key | :keyrest | :block, Symbol] | [:rest | :keyrest] ] # Returns the bound receiver of the method object. # # ```ruby # (1..3).method(:map).receiver # => 1..3 # ``` def receiver: () -> untyped # Returns the Ruby source filename and line number containing this method # or nil if this method was not defined in Ruby (i.e. native). def source_location: () -> [String, Integer]? # Returns a [Method](Method.downloaded.ruby_doc) of superclass which would # be called when super is used or nil if there is no method on superclass. def super_method: () -> Method? # Dissociates *meth* from its current receiver. The resulting # `UnboundMethod` can subsequently be bound to a new object of the same # class (see `UnboundMethod` ). def unbind: () -> UnboundMethod end