Skip to content

Instantly share code, notes, and snippets.

@Tux
Created December 5, 2015 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tux/afec03490da258d48671 to your computer and use it in GitHub Desktop.
Save Tux/afec03490da258d48671 to your computer and use it in GitHub Desktop.
Not OK (yet)
class IO::String is IO::Handle {
has $.nl-in is rw;
has Str @!content;
multi method new (Str $str!) {
my \obj = self.bless;
obj.nl-in = $*IN.nl-in;
obj.print ($str);
obj;
}
method print (*@what) {
if (my Str $str = @what.join ("")) {
my Str @x = $str.split (self.nl-in);
@x[*] eq "" and @x.pop;
my $nl = self.nl-in[0];
@!content.push: |@x.map ({ $_ ~ $nl });
}
self;
}
method print-nl {
self.print ($.nl);
}
method get {
@!content or return Str;
shift @!content;
}
method Str {
@!content.join ("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment