On 2020-08-30 08:16, yary wrote:
Expanding on how to read the docs & signature a bit, from Tobias

    You confuse two methods that have the same name "lines". One of them,
    which exists in the IO::Path class, has a :chomp argument. The other,
    on IO::Handle does not.
       "path".IO.lines()       <-- calls lines on an IO::Path (supports
    :chomp)
       "path".IO.open.lines()  <-- calls lines on an IO::Handle (does
    not support :chomp)


Looking up https://docs.raku.org/routine/lines shows a Table of Contents with

    class Cool
    (Cool) routine lines
    class Supply
    (Supply) method lines
    class Str
    (Str) routine lines
    class IO::CatHandle
    (IO::CatHandle) method lines
    class IO::Path
    (IO::Path) method lines
    class IO::Handle
    (IO::Handle) routine lines
    class IO::Socket::INET
    (IO::Socket::INET) method lines


Lots of different "lines" methods. If I click on IO::Handle it jumps to
sub          lines( $what = $*ARGFILES, |c)
multi method lines( IO::Handle:D: $limit, :$close )
multi method lines( IO::Handle:D:         :$close )

which indeed has no named argument for "chomp"

As an aside-Reading between the lines (no pun intended), I deduce that the IO::Handle "lines" method is its own implementation so that it can read "lazily" as needed, and to support the "close" option.

And as another aside, it has a "sub" which shows that when "lines" is called with no arguments, it defaults to reading from $*ARGFILES.

So, back to the table of contents. How does one know which "lines" routine to look at?

Either by thinking & remembering --
"oh 'file'.IO.open returns an IO::Handle that's the one to read"
"Huh 'file'.IO returns a path object, and there's /'(IO::Path) method/ /lines'/ listed lets look at that, hmm it has /chomp/"

or by experiment!
 > 'example.txt'.IO.WHAT
(Path)
 > 'example.txt'.IO.open.WHAT
(Handle)

-y

Thank you!

Reply via email to