|
20 | 20 | "19": {"lang": "EN", "title": "Sadly, You Hate Toast Poetry", "chapter": "N", "answer": "(toast)%7B0%7D", "ok": "Excellent", "error": "Still%20smells%20like%20toast%20to%20me", "text": "%3Cp%3ELook,%20it’s%20okay.%20You%20don’t%20have%20to%20like%20it.%20Hack%20it%20up,%20be%20my%20guest.%20Instead%20of%20toast,%20go%20for%20a%0Amelon%20or%20something.%20Try%20this%20to%20see%20the%20new%20poem:%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Epoem.gsub("toast",%20"honeydew")%0A%3C/code%3E%3C/pre%3E%0A%0A%3Cp%3EThe%20%3Cstrong%3Egsub%3C/strong%3E%20method%20is%20short%20for%20global%20substitute.%20It%20replaces%20all%20occurences%20of%20“toast”%20with%0A“honeydew”.%3C/p%3E%0A", "load_code": "prev"}, |
21 | 21 | "20": {"lang": "EN", "title": "Ready, Aim", "chapter": "N", "answer": "%5E%5Cn.ti%20tae%20ot%20(.+)", "ok": "Okay,%20sure.%20%20So%20the%20whole%20poem%20has%20been%20turned%20backwards.", "error": "", "text": "%3Cp%3EHere’s%20a%20question:%20what%20happens%20when%20we%20reverse%20this%20whole%20poem?%20%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Epoem.reverse%0A%3C/code%3E%3C/pre%3E%0A", "load_code": "prev"}, |
22 | 22 | "21": {"lang": "EN", "title": "Too Much Reversal", "chapter": "N", "answer": "%5E%5C[%22More%20still%20did%20(.+)", "ok": "Yes,%20almost%20what%20we%20want", "error": "", "text": "%3Cp%3ESo%20the%20whole%20poem’s%20been%20turned%20backwards,%20letter-by-letter.%20I%20really%20wanted%20to%20just%20reverse%20the%20lines%20though.%0AMove%20the%20last%20line%20up%20to%20first%20and%20the%20first%20line%20down%20to%20last.%3C/p%3E%0A%0A%3Cp%3EBackwards,%20but%20not%20%3Cstrong%3Ethat%3C/strong%3E%20backwards.%3C/p%3E%0A%0A%3Cp%3EHere’s%20how:%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Epoem.lines.reverse%0A%3C/code%3E%3C/pre%3E%0A", "load_code": "prev"}, |
23 | | - "22": {"lang": "EN", "title": "Ringlets of Chained Methods", "chapter": "N", "answer": "%5EMore%20still%20did%20(.+)", "ok": "Good%20show,%20my%20friend!%20The%20join%20method%20took%20that%20array%20of%20lines%20and%20put%20them%20together%20into%20a%20string.", "error": "", "text": "%3Cp%3ESo%20what%20do%20you%20see?%20What%20happened%20there?%20You%20typed%20%3Cstrong%3Epoem.lines.reverse%3C/strong%3E%20and%20what%20happened?%3C/p%3E%0A%0A%3Cp%3ETwo%20things%20happened.%20You%20turned%20the%20poem%20into%20a%20list%20using%20lines.%0ALines%20decides%20the%20way%20the%20string%20is%20split%20up%20and%20converts%20it%20into%20an%20Array.%3C/p%3E%0A%0A%3Cp%3EThen,%20you%20reversed%20that%20list.%20You%20had%20each%20line.%20You%20reversed%20them.%20That’s%20it.%3C/p%3E%0A%0A%3Cp%3ELet’s%20tack%20one%20more%20method%20on%20the%20end%20there:%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Eputs%20poem.lines.reverse.join("%5Cn")%0A%3C/code%3E%3C/pre%3E%0A%0A%3Cp%3ECombining%20methods%20like%20this%20is%20called%20%3Cem%3Emethod%20chaining%3C/em%3E.%3C/p%3E%0A", "load_code": "prev"}, |
| 23 | + "22": {"lang": "EN", "title": "Ringlets of Chained Methods", "chapter": "N", "answer": "%5EMore%20still%20did%20(.+)", "ok": "Good%20show,%20my%20friend!%20The%20join%20method%20took%20that%20array%20of%20lines%20and%20put%20them%20together%20into%20a%20string.", "error": "", "text": "%3Cp%3ESo%20what%20do%20you%20see?%20What%20happened%20there?%20You%20typed%20%3Cstrong%3Epoem.lines.reverse%3C/strong%3E%20and%20what%20happened?%3C/p%3E%0A%0A%3Cp%3ETwo%20things%20happened.%20You%20turned%20the%20poem%20into%20a%20list%20using%20lines.%0ALines%20decides%20the%20way%20the%20string%20is%20split%20up%20and%20converts%20it%20into%20an%20Array.%3C/p%3E%0A%0A%3Cp%3EThen,%20you%20reversed%20that%20list.%20You%20had%20each%20line.%20You%20reversed%20them.%20That’s%20it.%3C/p%3E%0A%0A%3Cp%3ELet’s%20tack%20one%20more%20method%20on%20the%20end%20there:%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Eputs%20poem.lines.reverse.join%0A%3C/code%3E%3C/pre%3E%0A%0A%3Cp%3ECombining%20methods%20like%20this%20is%20called%20%3Cem%3Emethod%20chaining%3C/em%3E.%3C/p%3E%0A", "load_code": "prev"}, |
24 | 24 | "23": {"lang": "EN", "title": "Of All the Summaries, #3 is Here Now", "chapter": "Y", "answer": "%5C%7B%5C%7D", "ok": "You've%20made%20an%20empty%20hash%20!", "error": "", "text": "%3Ch3%3EExclamations%3C/h3%3E%0A%0A%3Cp%3EMethods%20may%20have%20exclamations%20(and%20also%20question%20marks)%20in%20their%20name.%0AThese%20are%20just%20there%20to%20better%20explain%20what%20their%20function%20is.%20No%20big%20deal.%3C/p%3E%0A%0A%3Ch3%3EString%20manipulation%3C/h3%3E%0A%0A%3Cp%3ESearch%20and%20change%20strings%3C/p%3E%0A%0A%3Ch3%3EChaining%3C/h3%3E%0A%0A%3Cp%3EChaining%20methods%20lets%20you%20get%20a%20lot%20more%20done.%20Break%20up%20a%20poem,%20reverse%20it,%20reassemble%20it:%0A%3Cstrong%3Epoem.lines.reverse.join%3C/strong%3E%3C/p%3E%0A%0A%3Cp%3EAt%20this%20point,%20you%20may%20want%20to%20tinker%20with%20the%20poem%20a%20bit%20more.%20A%20complete%20list%20of%20all%20the%20String%0Amethods%20is%20%3Ca%20href=%22http://ruby-doc.org/core/classes/String.html%22%20target=%22_blank%22%3Ehere%3C/a%3E.%3C/p%3E%0A%0A%3Cp%3EGo%20ahead%20and%20try%20a%20few,%20such%20as:%20poem.downcase%20or%20poem.swapcase%3C/p%3E%0A%0A%3Ch2%3EReady%20?%3C/h2%3E%0A%0A%3Cp%3EWhen%20you%20feel%20ready%20to%20move%20on,%20type:%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Ebooks%20=%20%7B%7D%0A%3C/code%3E%3C/pre%3E%0A", "load_code": "prev"}, |
25 | 25 | "24": {"lang": "EN", "title": "A Wee Blank Book", "chapter": "N", "answer": "%5E(splendid%7Cquite_good%7Cmediocre%7Cquite_not_good%7Cabyssmal)$", "ok": "Yes%20that's%20a%20new%20review", "error": "Use%20one%20of%20splendid,%20quite_good,%20mediocre,%20quite_not_good,%20abyssmal.%20Don't%20forget%20the%20colon", "text": "%3Cp%3EYou’ve%20made%20an%20empty%20%3Cstrong%3Ehash%3C/strong%3E.%20A%20hash%20is%20like%20an%20array,%20only%20every%20one%20of%20its%20elements%20has%20a%20name.%3C/p%3E%0A%0A%3Cp%3EWe’re%20going%20to%20stuff%20some%20miniature%20book%20reviews%20in%20our%20new%20hash.%20Here’s%20our%20rating%20system:%3C/p%3E%0A%0A%3Cul%3E%0A%3Cli%3E:splendid%20→%20a%20masterpiece%3C/li%3E%0A%3Cli%3E:quite_good%20→%20enjoyed,%20sure,%20yes%3C/li%3E%0A%3Cli%3E:mediocre%20→%20equal%20parts%20great%20and%20terrible%3C/li%3E%0A%3Cli%3E:quite_not_good%20→%20notably%20bad%3C/li%3E%0A%3Cli%3E:abyssmal%20→%20steaming%20wreck%3C/li%3E%0A%3C/ul%3E%0A%0A%3Cp%3ETo%20rate%20a%20book,%20put%20the%20title%20in%20square%20brackets%20and%20put%20the%20rating%20after%20the%20equals.%20For%20example:%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Ebooks["Gravitys%20Rainbow"]%20=%20:splendid%0A%3C/code%3E%3C/pre%3E%0A%0A%3Cblockquote%3E%0A%3Cp%3EBy%20now%20I%20think%20it%20is%20only%20fair%20to%20tell%20you%20that%20all%20lessons%20in%20TryRuby%20are%20separate%20from%20each%20other.%0ASo%20if%20you%20go%20crazy%20typing%20book%20reviews%20here,%20you%20can%20only%20use%20‘em%20in%20this%20lesson.%3Cbr%3E%0AIf%20you%20want%20to%20use%20your%20reviews%20in%20the%20next%20lesson%20you%20should%20copy/paste%20them.%3Cbr%3E%0ADon’t%20worry%20about%20this%20too%20much,%20each%20lesson%20has%20plenty%20of%20predefined%20stuff%20for%20you%20to%20play%20around%20with.%3C/p%3E%0A%3C/blockquote%3E%0A", "load_code": "books%20=%20%7B%7D"}, |
26 | 26 | "25": {"lang": "EN", "title": "More Bite-Size Reviews", "chapter": "N", "answer": "[3-9]", "ok": "See,%20the%20length%20method%20works%20on%20strings,%20array's%20and%20hashes.", "error": "", "text": "%3Cp%3EKeep%20going,%20fill%20it%20up%20with%20reviews.%20And,%20if%20you%20want%20to%20see%20the%20whole%20list,%20just%20type:%20%3Cstrong%3Eputs%20books%3C/strong%3E%3C/p%3E%0A%0A%3Cp%3EAgain,%20the%20ratings%20are:%20:splendid,%20:quite_good,%20:mediocre,%20:quite_not_good%20and%20:abyssmal.%3C/p%3E%0A%0A%3Cp%3EThese%20ratings%20are%20not%20strings.%20When%20you%20place%20a%20colon%20in%20front%20of%20a%20simple%20word,%20you%20get%20a%20%3Cstrong%3Esymbol%3C/strong%3E.%0ASymbols%20are%20cheaper%20than%20strings%20(in%20terms%20of%20computer%20memory.)%20If%20you%20use%20a%20word%20over%20and%20over%20in%20your%20program,%0Ause%20a%20symbol.%20Rather%20than%20having%20thousands%20of%20copies%20of%20that%20word%20in%20memory,%20the%20computer%20will%20store%20the%20symbol%20only%0A%3Cstrong%3Eonce%3C/strong%3E.%3C/p%3E%0A%0A%3Cp%3EMore%20importantly,%20a%20symbol%20tells%20you%20that%20is%20not%20just%20any%20old%20word%20but%20has%20a%20meaning%20within%20your%20program.%3C/p%3E%0A%0A%3Cp%3EEnter%202%20more%20bookreviews,%20use%20%3Cstrong%3Ebooks.length%3C/strong%3E%20to%20see%20how%20many%20reviews%20there%20are%20in%20the%20hash:%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Ebooks["The%20deep%20end"]%20%20=%20:abyssmal%0Abooks["Living%20colors"]%20=%20:mediocre%0A%0Aputs%20books%0A%0Aputs%20books.length%0A%3C/code%3E%3C/pre%3E%0A", "load_code": "books%20=%20%7B%22Gravitys%20Rainbow%22%20=%3E%20:splendid%7D"}, |
|
0 commit comments