January 6, 2018

Learning Ruby

When it comes to programming languages, I am pretty language agnostic. With only three years of work experience developing automation, I am still learning, adopting whatever toolsets and technologies my employer already is using.

Sure, I still prefer Java, but only because it was my primary language back in grad school. Although I only consider myself a junior Java developer, I still think of it as my mother tongue.
  • 2014: As the manual tester supervising an offshore automation team, I tested out and tinkered with the Calabash / Ruby code they were using to automate mobile apps.
  • 2015: Selenium WebDriver/ Java was used to write the automation framework in my first job as an automation developer.
  • 2016: Pairing with the Node.js product, I adopted Nightwatch.js to write tests for a Vue.js JavaScript-based front end.
  • 2017: Appium / Java was selected in a mobile testing proof-of-concept I was creating.
  • 2018: My new upcoming SDET job uses Chef. Chef uses Ruby. Therefore I need to re-learn Ruby. 
But where to start re-learning Ruby?

What The Heck is Ruby?

"Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

"Ruby was created as a language of careful balance. Its creator, Yukihiro “Matz” Matsumoto, blended parts of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balanced functional programming with imperative programming.

"He has often said that he is "trying to make Ruby natural, not simple," in a way that mirrors life.

"Building on this, he adds: "Ruby is simple in appearance, but is very complex inside, just like our human body."

"You can read more about the Ruby language on its site". - Exercism / Ruby / About

Get Your Feet Wet:

Ruby comes with IRB, the Interactive Ruby Shell, a REPL (Read / Evaluate / Print Loop) you can use to test out new code. Figure out how on Ruby-lang.org, the official site!

Start Learning the Fundamentals:

  • If you are brand new to coding, I would say that you should work first through Zed Shaw's "Learning Ruby The Hard Way", written for the non-coder, good for the manual tester learning the first programming language. Since I always feel shaky first learning a new language, I started here.
  • CodeAcademy has a Learn Ruby course that is absolutely free! It will take you through Looping, Data Structures such as Arrays, Hashes, Blocks, Procs, Lambdas, and lessons in Object Oriented programming. I really enjoyed this course!
  • Ruby-Doc.org shows the API documentation for Ruby 2.5.0, released December 2017. Practice looking up new Ruby keywords on Ruby-doc.org while you are reading any Ruby programming book.
  • Ruby-lang.org, the official site for the Ruby Language. Start exploring the tutorials there.
  • Programming Ruby: The Pragmatic Programmer's Guide, for intermediate developers, is free on the web! I may not have understood all I read, but I plowed through the book within a week.
Just like Java libraries can be accessed in http://mvnrepository.com and Node.JS libraries can be accessed in https://www.npmjs.com/:

For Unit Tests there is:
Do I really need to know all of this Ruby code to learn Chef and Kitchen?

... Maybe not. But my goal, when I learn automation, is to learn more than just running the automation tool itself. My goal is to code as well as a software developer!  

Keep Practicing!

Another way to practice? Exercism.io.

Franklin Webber, the Chef specialist and Ruby developer who developed the webinar, The Ruby Behind Chef, recommended another way to keep practicing: a site called Exercism.io, an open-source project that anyone can use to "Level Up Your Programming Skills".

A future blog entry will chart my experience with the Exercism site.

Rudimentary Ruby

Here's a bit of practice that I did after getting to know the basics and reading the Ruby docs:

Let's see what a String can do in Ruby using the Ruby-doc.org core docs.

puts "hello world"      # Prints out the String object, "hello world"
puts "hello world".capitalize  # "Hello World"
puts "hello world".clear  # ""
puts "hello world".count  # 11 letters
puts "hello world.delete "h" # "ello world"
puts "HELLO WORLD".downcase # "hello world"
puts "hello world".insert(6, 'there ') # "hello there world"
puts "hello world".length # Length of 11
puts "hello world".reverse # "dlrow olleh"
puts "hello world".upcase # "HELLO WORLD"
puts "hello world".split # Returns two words: "hello" and "world"

Array, in Docs.Ruby-Lang.org:

puts browsers = ["Chrome", "Firefox", 'MS Edge'] # Lists Chrome, then Firefox, then MS Edge
puts "Number of Browsers: #{browsers.length}" # Number of Browsers: 3
browsers.each { |x| puts "#{x}: Loading browser... " }

Yes! I am now halfway done with CodeAcademy!

As soon as I am done with the CodeAcademy course in Ruby, where I really am getting familiar with the fundamentals of the language, I can start stretching myself with Exercism.io.

See you then! Happy Testing!

-T.J. Maher
Twitter | LinkedIn | GitHub

// Sr. QA Engineer, Software Engineer in Test, Software Tester since 1996.
// Contributing Writer for TechBeacon.
// "Looking to move away from manual QA? Follow Adventures in Automation on Facebook!"

No comments: