Sha256: bda77d67a548de3714db0511c09f64bd0b378236a2ef9948e07cdd9eab4ec6e8
Contents?: true
Size: 682 Bytes
Versions: 48
Compression:
Stored size: 682 Bytes
Contents
package Clock 2; use strict; use warnings; use POSIX; sub new { my ($class, $attributes) = @_; my $self = { hour => $attributes->{hour} || 0, minute => $attributes->{minute} || 0, }; return bless($self, $class)->BUILD; } sub time { my ($self) = @_; return sprintf '%02d:%02d', $self->{hour}, $self->{minute}; } sub add_minutes { my ($self, $amount) = @_; $self->{minute} += $amount; return $self->BUILD; } sub subtract_minutes { my ($self, $amount) = @_; return $self->add_minutes(-$amount); } sub BUILD { my ($self) = @_; $self->{hour} = ( $self->{hour} + floor($self->{minute} / 60) ) % 24; $self->{minute} %= 60; return $self; } 1;
Version data entries
48 entries across 48 versions & 1 rubygems