O'Reilly logo

Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 49. Making Sentences

What we should be able to get from our little game lexicon scanner is an array that looks like this:

Exercise 49 Ruby Session

>> require './ex48/lexicon.rb' => true >> Lexicon.scan("go north") => [["verb", "go"], ["direction", "north"]] >> Lexicon.scan("kill the princess") => [["verb", "kill"], ["stop", "the"], ["noun", "princess"]] >> Lexicon.scan("eat the bear") => [["verb", "eat"], ["stop", "the"], ["noun", "bear"]] >> Lexicon.scan("open the door and smack the bear in the nose") => [["error", "open"], ["stop", "the"], ["error", "door"], ["error", "and"],     ["error", "smack"], ["stop", "the"], ["noun", "bear"], ["stop", "in"],     ["stop", "the"], ["error", "nose"]]

Now let us turn ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required