I am new to ruby and I can't understand why I after running this code I get an extra empty line as a result as a part of the output. I am using Ruby 2.5.3
class Card
attr_accessor :rank, :suit
def initialize(rank,suit)
@rank = rank
@suit = suit
end
def output_card
puts "#{self.rank} of #{self.suit}"
end
def self.random_card
suit = ["hearts", "spades", "clubs", "diamonds"]
Card.new(rand(1..13), suit.sample)
end
end
class Deck
def initialize
d = 0
@cards =[]
while d < 13
@cards << Card.random_card
d += 1
end
end
def shuffle
@cards.shuffle!
end
def output
@cards.each do |card|
card.output_card
end
end
def deal
self.shuffle
dealing = @cards.shift
puts "#{dealing.output_card}"
end
end
deck = Deck.new
deck.deal
The above will give me this result:
[ENV]:/vagrant/OOP $ ruby card.rb
6 of clubs
[ENV]:/vagrant/OOP $
As you can see there is an extra line, and I don't understand why.