Snippets

sironekotoro Perlでダックタイピング

Created by sironekotoro
use strict;
use warnings;
use feature qw/say/;

# https://ja.wikipedia.org/wiki/ダック・タイピング

unless (caller) {
    say Duck->new->sound;    # quack
    say Cat->new->sound;     # myaa
}

package Duck;

sub new {
    my $class = shift;
    return bless \{}, $class;
}

sub sound {
    return 'quack';
}

package Cat;

sub new {
    my $class = shift;
    return bless \{}, $class;
}

sub sound {
    return 'myaa';
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.