class FiftyTwo::Card

Attributes

deck[R]
rank[R]
suit[R]

Public Class Methods

new(deck, rank, suit) click to toggle source
# File lib/fiftytwo/card.rb, line 12
def initialize(deck, rank, suit)
  @deck = deck
  @rank = rank
  @suit = suit
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/fiftytwo/card.rb, line 35
def <=>(other)
  [rank, suit] <=> [other.rank, other.suit]
end
code() click to toggle source
# File lib/fiftytwo/card.rb, line 18
def code
  "#{rank.code}#{suit.code}"
end
identifier() click to toggle source
# File lib/fiftytwo/card.rb, line 27
def identifier
  "#{rank.identifier}#{suit.identifier}"
end
method_missing(name, **args, &block) click to toggle source
Calls superclass method
# File lib/fiftytwo/card.rb, line 39
def method_missing(name, **args, &block)
  return super unless name.to_s.ends_with?("?")

  attributes.each do |attribute|
    return attribute.send(name) if attribute.respond_to?(name)
  end

  super
end
name()
Alias for: to_s
render() click to toggle source
# File lib/fiftytwo/card.rb, line 31
def render
  code.rjust(3).send(suit.color.name)
end
respond_to_missing?(name, include_private = false) click to toggle source
# File lib/fiftytwo/card.rb, line 49
def respond_to_missing?(name, include_private = false)
  return false unless name.to_s.ends_with?("?")
  return false unless attributes.any? { |a| a.respond_to?(name) }
end
to_s() click to toggle source
# File lib/fiftytwo/card.rb, line 22
def to_s
  "#{rank} of #{suit}"
end
Also aliased as: name

Private Instance Methods

attributes() click to toggle source
# File lib/fiftytwo/card.rb, line 56
def attributes
  [rank, suit]
end