I'm trying to write a coin flip program where I can analyze the percentage of Heads flipped. I've gotten coin flip to work, just not the actually analyzing yet.
The problem is when I created a Coin class in order to further break down the object into something like Coin.length afterwards.
Why am I getting an "undefined method 'flip' for Coin:Class (NoMethodError)" from flip.rb:14:in 'times'
from flip.rb:14:in <main>
when I indeed have one?
class Coin
def flip
flip = 1 + rand(2)
if flip == 2
then puts "Heads"
else
puts "Tails"
end
end
end
10.times do
Coin.flip
end
Here's a die roll example that I am somewhat trying to emulate:
class Die
def roll
1 + rand(6)
end
end
# Let's make a couple of dice...
dice = [Die.new, Die.new]
# ...and roll them.
dice.each do |die|
puts die.roll
end