Sha256: de2e475a6b60d61259982053e8123e1abddba13a9d3ee17ce91848ab9c8e732a
Contents?: true
Size: 557 Bytes
Versions: 73
Compression:
Stored size: 557 Bytes
Contents
package Allergies; use strict; use warnings; use List::Util 'first'; my @allergens = qw(eggs peanuts shellfish strawberries tomatoes chocolate pollen cats); sub new { my ($class, $score) = @_; my $self = bless {} => $class; $self->{score} = reverse sprintf "%08b", $score; return $self; } sub allergic_to { my ($self, $allergen) = @_; my $index = first { $allergens[$_] eq $allergen } 0..$#allergens; return substr $self->{score}, $index, 1; } sub list { [ grep { $_[0]->allergic_to($_) } @allergens ] } __PACKAGE__;
Version data entries
73 entries across 73 versions & 1 rubygems