Slide 1

Slide 1 text

RUBY KOANS GETTING STARTED

Slide 2

Slide 2 text

CORINNA BROCK Email: [email protected] Blog: cjbrock.github.com Github: github.com/cjbrock Twitter: @cjnboston

Slide 3

Slide 3 text

WHAT IS A KOAN? a paradox to be meditated upon that is used to train Zen Buddhist monks to abandon ultimate dependence on reason and to force them into gaining sudden intuitive enlightenment -- merriamwebster.com

Slide 4

Slide 4 text

ABOUT THE KOANS “The Koans walk you along the path to enlightenment in order to learn Ruby. The goal is to learn the Ruby language, syntax, structure, and some common functions and libraries. We also teach you culture. Testing is not just something we pay lip service to, but something we live. It is essential in your quest to learn and do great things in the language. --rubykoans.com

Slide 5

Slide 5 text

WHAT IS TESTING? •  Ruby is a test driven development language •  In test-driven development the mantra has always been: •  red : write a failing test and run it, •  green : write just enough code to make the test pass, and •  refactor : look at the code to see if you can make it any better. •  Some common testing gems: •  Cucumber •  Turnip •  Steak

Slide 6

Slide 6 text

STARTING DETAILS •  Download, don’t web-base •  RubyKoans does offer you the option to web-base, which is a good option if you want to practice but are not on your local machine •  Push repository to Github

Slide 7

Slide 7 text

STARTING THE KOANS •  Terminal: ruby path_to_enlightenment.rb •  Error messages contain: •  File name •  Line number

Slide 8

Slide 8 text

ABOUT ASSERTS •  The first testing set instructs you in what to replace to help get you used to testing syntax. •  It clearly tells us to do this:

Slide 9

Slide 9 text

ABOUT ASSERTS And our test passes!

Slide 10

Slide 10 text

TRY IN IRB: ABOUT NIL •  Our next class, about nil, gives us the first chance to test things in IRB. Here is the first test in about nil: •  Let’s test this in IRB:

Slide 11

Slide 11 text

TRY IN IRB: ABOUT NIL •  We change the __ to true, and run ruby path_to_enlightenment.rb again, and our test passes.

Slide 12

Slide 12 text

DEALING WITH EXCEPTION TESTING •  The next assert asks us to provide the error raised when nil doesn’t know about a method. This is another great one to try in IRB.

Slide 13

Slide 13 text

DEALING WITH EXCEPTION TESTING •  Again, copy and paste the method call into IRB: •  So the solution to this assert is as follows:

Slide 14

Slide 14 text

INHERITANCE •  Ruby Koans gives a clear and concise view of Inheritance. It defines a class, sets up two methods, illustrates how traits are both inherited and not passed up. The class is established as follows:

Slide 15

Slide 15 text

INHERITANCE •  The inheritance assert about subclasses:

Slide 16

Slide 16 text

INHERITANCE

Slide 17

Slide 17 text

INHERITANCE •  And we see that again, we get a NoMethodError.

Slide 18

Slide 18 text

I hope you find enlightenment!