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 ...

Get Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.