Ha yes I wasn’t shocked at the fact that it worked. It was more that when i was complicating it further with if and else statements it just wasn’t happening. I guess Ruby prefers simplicity then excessive/complicated coding.
I see how you have done your code. Its probably the best way to code but I wouldn’t have known this as I only learnt this in further lessons now.
I was actually stuck on the following too. I guess the question didn’t make any sense to me tbh:
Topic: Converting Between Symbols and Strings:
We have an array of strings we’d like to later use as hash keys, but we’d rather they be symbols.
- Create a new variable, symbols, and store an empty array in it.
- Use .each to iterate over the strings array.
- For each s in strings, use .to_sym to convert s to a symbol and use .push to add that new symbol to symbols.
- Print the symbols array.
I have now spent an hour on this trying to figure out what they mean by point ‘3’. It is rather confusing as I am understanding that for every ‘s’ within a ‘string’ it should convert it to a symbol but when it finally changed the code to the following it changed each string to a symbol including the ones that did not have a ‘s’ in them. I don’t know whether my understanding of this point was wrong or the question itself is wrong. Your thoughts would be appreciated.
symbols = 
strings.each do |s|