develooper Front page | perl.perl6.users | Postings from July 2018

What does ^methods really tell you?

Thread Next
From:
Joseph Brenner
Date:
July 31, 2018 02:26
Subject:
What does ^methods really tell you?
Message ID:
CAFfgvXX2bzBRPAhWCV3U6HPOYZBkkZNGD0OnoqRD8cZWreG-9A@mail.gmail.com
I originally thought that $var.^methods gave you a list of all
available methods on $var, but it looks like it doesn't (always?)
report on inherited methods.

my $stringy = '3.14159';
say $stringy.^name;
  # Str
say $stringy.^mro;
  # ((Str) (Cool) (Any) (Mu))

The list returned from checking $stringy is the same as just
checking (Str):

  $stringy.^methods
  (Str).^methods

And it includes none of the (Cool) methods:

  (Cool).^methods

For example, trig functions like "cos" are part of the (Cool)
list, but are not in the $stringy.^methods list, though you can
call clearly them:

  say $stringy.cos
  -0.9999999999964793

I guess this seems to work to give you the full list of available
methods:

  $stringy.^methods(:all)

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About