jeudi 12 mars 2020

How to store a value in a conditional statement and call it in ruby

Method

def myname(generate_name)
  if generate_name
    name = SecureRandom.urlsafe_base64(6)   
    name //ex:abcdef

call

myname(true)    //output abcdef
myname(false)   //expected output abcdef

In my code, i have to use myname(true) to generate unique name every time the function is referred.

Question: i need the value "abcdef" to be the output when i call myname(false)

Aucun commentaire:

Enregistrer un commentaire