Sha256: 862901f6f896afe46bd7eaed31f5d2207765cb4b1ad00afe574422d3e4543e09
Contents?: true
Size: 926 Bytes
Versions: 5
Compression:
Stored size: 926 Bytes
Contents
# frozen_string_literal: true require_relative "./suit/color" module FiftyTwo class Suit include Comparable attr_reader :name, :color, :symbol alias_method :code, :symbol def initialize(name, color, symbol = nil) @name = name @color = color @symbol = symbol end ALL = [ CLUBS = Suit.new("clubs", Color::BLACK, "♣").freeze, DIAMONDS = Suit.new("diamonds", Color::RED, "♦").freeze, HEARTS = Suit.new("hearts", Color::RED, "♥").freeze, SPADES = Suit.new("spades", Color::BLACK, "♠").freeze ] Color::ALL.each do |color| define_method("#{color.name}?") { self.color == color } end ALL.each do |suit| define_method("#{suit.name.downcase}?") { self == suit } end def <=>(other) name <=> other.name end def to_s name.titleize end def identifier name[0].upcase end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
fiftytwo-0.0.5 | lib/fiftytwo/suit.rb |
fiftytwo-0.0.4 | lib/fiftytwo/suit.rb |
fiftytwo-0.0.3 | lib/fiftytwo/suit.rb |
fiftytwo-0.0.2 | lib/fiftytwo/suit.rb |
fiftytwo-0.0.1 | lib/fiftytwo/suit.rb |