Exercise 49. Making Sentences

Image

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

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

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