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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.