Alex Alex - 4 years ago 169
Ruby Question

Ruby rand function in method

Using Ruby why can't I pass random variable here? I tried different combinations such as removing numbers.

money= rand(100)

def paycheck(money)
"Lets make this amount, #{money} today"

puts paycheck("100")
puts paycheck("200")
puts paycheck("500")

Answer Source

You can:

money= rand(100)
puts paycheck(money)

When you define your method paycheck(money) - it is different variable money that the one on this line: money = rand(100)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download