![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj83rC2iI0MTGSLRWsqZVNpQCfXS6wWa9OMD3l8j3NNH2vogx6_ChK5UWIvkoXnekJyBd0ceTl7RJ0neJdMO4lBg6cJW7Ot0I2-rxFisuZWRxxwcZTB3H062SUxcputFURVaICv/s200/Ruby.jpeg)
Tests first (very minimal - I'm a bit pressed for time):
require './consistent' require 'test/unit' class TestUntitled < Test::Unit::TestCase def test_consistent_phone_list list = { 'Bob' => '91125426', 'Alice' => '97625992', } assert consistent(list) end def test_inconsistent_phone_list list = { 'Bob' => '91125426', 'Alice' => '97625992', 'Emergency' => '911' } assert !consistent(list) end endCode second:
def consistent(list) list.values.sort.each_cons(2).none? { |pair| prefix(*pair) } end def prefix(lhs,rhs) rhs.start_with? lhs endThe each_cons from the previous problem proved very handy here. As did none? I really feel I'm starting to get the hang of ruby. You can replay my entire progression (warts and all) on Cyber-Dojo (naturally).