How to match a symbol with a string in Ruby -


i have array contains both string , symbol

in function getting string check if array contains or not.

array = ["day",:night]  def check(name)     if array.include? name or array.include? name.to_sym          return true     else          return false    end end 

if input "day" returns true. if input "night" returns false. want return true in case of "night" converted check if symbol same name exists.

how can make function work compares symbol (:night) string ("night") , returns true?

def check(name, array)   array.map(&:to_s).include?(name.to_s) end  array = ["day",:night]  check("day", array)   #=> true check(:day, array)    #=> true check("night", array) #=> true check(:night, array)  #=> true check("cat", array)   #=> false 

Popular posts from this blog

java - Cannot send AES encrypted messages of over 47 characters -

php - How to set default value of a select dynamically from database using smarty? -

telerik - Reformat image format in PDF -