A few years back I dabbled in trying to learn Ruby on Rails, but I made the mistake of trying to teach myself both the language and the framework at the same time. That led to mostly confusion and frustration. I've heard many different opinions on this subject, but I now strongly believe that you should have a firm grasp of the language before trying to learn one of its frameworks.
For the past year or so I've been focusing solely on Ruby, primarily by consuming Team Treehouse's Learn Ruby track. It's a 20-hour course in all and I'm stoked to have finally completed it! Next up: Rails!
While moving through the Ruby course I took copious notes. I thought it would be helpful to share those notes here. Enjoy!
All notes below were written by, based on the Team Treehouse course mentioned above. Red text indicates a key concept.
my_string = <<-HERE
I am a string
that is defined across
Below is a good example of someone brand new to Ruby (me!) and someone with Ruby experience (not me!) solving the exact same problem. These two methods have the same goal: accept a string, reverse and return it.
def solution(sentence) sentence_as_array = sentence.split(" ").reverse! reversed_string = "" sentence_as_array.each do |x| reversed_string = reversed_string + x + " " end return reversed_string.chop end def better_solution(sentence) sentence.split(" ").reverse.join(" ") end
It's crazy how much more elegant the second method is.