Re: I'm confused about Ruby.2.5.3 Method#arity for Dir.entries and Dir#entries

Colin Bartlett <[email protected]> Tue, 5 Nov 2019 14:41:02 +0000
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAKtK3JqHTp8S0FZrkkN4q-iN1CSNUMFddDLzfj1pFCvzp31+zw@mail.gmail.com>
On Thu, Oct 17, 2019 at 3:37 AM Frank J. Cameron <[email protected]> wrote:

> ...
> In the ... section of your quote from the docs: "[arity] For methods
> written
> in C, returns -1 if the call takes a variable number of arguments."
>
> Dir.entries is indeed written in C:
> ...
>

Thank you. I clearly didn't look closely enough at the whole Method#arity
description, which is:
https://ruby-doc.org/core-2.5.3/Method.html#method-i-arity
Method#arity:
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.

My apologies for my delay in responding: I'd sort of forgotten that I'd
asked this question, and ironically (?) I now can't remember why.

I think I was trying to write something that used a method (quite possibly
Dir.entries) which might differ between different Ruby versions, and
Method#arity was a kludgy way to find out (at least roughly) what arguments
the method took.

Anyway, thank you for your reply.


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>