vendredi 30 juin 2017

Is there a way to call methods of a specific class randomly in ruby?

I was wondering if it is possible to do something like this:

class Something
  def A
    puts "A"
  end
  def B
    puts "B"
  end
  def C
    puts "C"
  end
  def D
    puts "D"
  end
end

y = Something.new
x = Random.new
x.rand(y)

then get a random result of "Something" class




Aucun commentaire:

Enregistrer un commentaire