\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{laurennicoleroth} \pdfinfo{ /Title (rubyforbeginners.pdf) /Creator (Cheatography) /Author (laurennicoleroth) /Subject (RubyForBeginners Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3200B} \definecolor{LightBackground}{HTML}{F9F1EF} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{RubyForBeginners Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{laurennicoleroth} via \textcolor{DarkBackground}{\uline{cheatography.com/26292/cs/7316/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}laurennicoleroth \\ \uline{cheatography.com/laurennicoleroth} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 25th February, 2016.\\ Updated 12th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Ruby Variables}} \tn % Row 0 \SetRowColor{LightBackground} local variable & local\_variable \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} instance variable & @instance\_variable \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} class variable & @@class\_variable \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} global variable & \$global\_variable \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Ruby Data Types}} \tn % Row 0 \SetRowColor{LightBackground} String & `"Sequence of characters."` or `'Sequence of characters.'` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Symbol (identifier) & `:a\_symbol, :another\_symbol, :name` \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Integer & `42, 100, 1002, -256` \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} Float (floating point) & `1.1, 3.1415926, 5.5, -128.6` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Numeric Methods & `+, -, *, /, \%` \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} Comparison Operators & `==, !=, \textgreater{}, \textgreater{}=, \textless{}, \textless{}=` \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} Return Value & Last line of a ruby method/block/expression in IRB \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} Boolean & `true` or `false` \tn % Row Count 15 (+ 1) % Row 8 \SetRowColor{LightBackground} `nil` & counts as false in Ruby, everything counts as true \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} Array (0 indexed) & `letters = {[}"a", "b", "c"{]}` \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} `letters{[}2{]}` & \#returns "c" \tn % Row Count 20 (+ 1) % Row 11 \SetRowColor{white} `letters{[}1{]} = "monkey"` & `{[}"a", "monkey", "c"{]}` \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{ERB}} \tn % Row 0 \SetRowColor{LightBackground} ERB & Embedded Ruby for making dynamic HTML templates \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `erb :hello` & Sinatra looks in "views" folder for hello.erb file \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Show @tweets & \textless{}\% if @tweets \%\textgreater{} \textless{}\% @tweets.each do |tweet| \%\textgreater{} \textless{}p\textgreater{}\textless{}\%= tweet \%\textgreater{}\textless{}/p\textgreater{} \textless{}\% end \%\textgreater{} \textless{}\% end \%\textgreater{} \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} Instance Variables & Any instance variables you declare in your routes, will be accessible in these erb files \tn % Row Count 12 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.18988 cm} x{2.78712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Ruby Expressions}} \tn % Row 0 \SetRowColor{LightBackground} `seen\_it = "seen again"` & Save string to variable \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `num = 3` & Save integer to variable \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `other\_num = 5` & Save another integer to another variable \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} `answer = (num + other\_num) * 6` & Save result of adding/multiplying. \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{String Interpolation}} \tn % Row 0 \SetRowColor{LightBackground} `dog\_speak = "woof!"` & `puts "Dogs say \#\{dog\_speak\}"` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} or & `puts "Dogs say " + dog\_speak` \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Conditionals}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{if/else} & `if input == admin\_password` \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & `admin\_logged\_in = true` \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & `else` \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} & `puts "Sorry, wrong password."` \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} & `end` \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.94563 cm} x{4.03137 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Useful Ruby Methods}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{`split`} & Breaks a string into an array. \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `join` & Takes an array and joins into a string. \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{`upcase`} & Makes characters capital letters. \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{`reverse`} & Reverse characters in a string. \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{`sample`} & Randomly choose element. \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} `map` & Do the same thing to every element. \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.53827 cm} x{2.43873 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Research}} \tn % Row 0 \SetRowColor{LightBackground} Cmd+Click (Mac) or Ctrl+Click & Open links in new tabs. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} ruby-doc.org ("The Ruby Docs") & Ruby coding best practices. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Stack Overflow & Oops. Research your error. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Guides and blog posts & Has someone done this before? \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.9908 cm} x{2.9862 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Sinatra}} \tn % Row 0 \SetRowColor{LightBackground} Sinatra & Framework for building a web server written in Ruby \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Routing & Action taken in response to request \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Path & text and slashes after domain \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{http://localhost:4567/hello} & Sinatra looks for `get '/hello'` \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} & `get '/hello' do` \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} & `\#code to return a response to the browser` \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} & `end` \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} String Response & `get '/hello'` \tn % Row Count 14 (+ 1) % Row 8 \SetRowColor{LightBackground} & `"Hello, friendly web traveler!"` \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} & `end` \tn % Row Count 17 (+ 1) % Row 10 \SetRowColor{LightBackground} HTML File Response & `get '/hello' do` \tn % Row Count 19 (+ 2) % Row 11 \SetRowColor{white} & `erb :hello` \tn % Row Count 20 (+ 1) % Row 12 \SetRowColor{LightBackground} & `end` \tn % Row Count 21 (+ 1) % Row 13 \SetRowColor{white} Get tweets route & `get '/' do` \tn % Row Count 22 (+ 1) % Row 14 \SetRowColor{LightBackground} & `@tweets = \seqsplit{\$client.user\_timeline.map} \{ |tweet| tweet.text \}` \tn % Row Count 25 (+ 3) % Row 15 \SetRowColor{white} & `erb :index` \tn % Row Count 26 (+ 1) % Row 16 \SetRowColor{LightBackground} & `end` \tn % Row Count 27 (+ 1) % Row 17 \SetRowColor{white} `Redirect '/'` & Get server to run code in get '/' route \tn % Row Count 29 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Array Methods}} \tn % Row 0 \SetRowColor{LightBackground} `push` & Add to end of array: `letters \textless{}\textless{} "elephant"` or \seqsplit{`letters.push("elephant")`} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `\textless{}\textless{}` & Shovel operator. Push to end of array. \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} `unshift` & Add element to beginning of array: \seqsplit{`letters.unshift("zebra")`} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} `pop` & Remove from end of array. `letters.pop` \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} `shift` & Remove from start of array. `letters.shift` \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{`.method(arguments)`} & Call a method with arguments. Some methods require no arguments. \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{`letters.pop`} & Method without arguments. \tn % Row Count 16 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Hashes}} \tn % Row 0 \SetRowColor{LightBackground} Instantiate a Hash (hash rockets) & `person = \{:name =\textgreater{} "Lauren", :age =\textgreater{} 89, :sex =\textgreater{} "female"\}` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Instantiate a Hash (shortcut) & `person = \{name: "Lauren", age: 89, sex: "female"\}` \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Access value by key. & `person{[}:name{]} \# returns "Lauren"` \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} Update value by key. & `person{[}:age{]} = 12` \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} Insert key, value pair. & `person{[}:gender{]} = "cis female"` \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} Remove value by key. & `person.delete(:sex) \# returns "female"` \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Methods}} \tn % Row 0 \SetRowColor{LightBackground} Greeting Method Accepts Name & `def \seqsplit{create\_greeting(name)`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & `return "Welcome, \#\{name\}"` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} & `end` \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} Call Greeting Method & \seqsplit{`create\_greeting("Lauren")`} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} & `\#returns 'Welcome, Lauren"` \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} Upcase On Call To Greeting Method & \seqsplit{`create\_greeting("Lauren")}.upcase` \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} Arguments & Input given to methods. \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} Parameters & Define what can be passed to a method. \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} Return value & Output from a function \tn % Row Count 16 (+ 1) % Row 9 \SetRowColor{white} Implicit Return & Returning last line of method without explicit "return" \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Command Line}} \tn % Row 0 \SetRowColor{LightBackground} Ruby gems & Download, install, and use ruby software packages on your system \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `\$ ruby -v` & Get Ruby Version \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} `\$ irb` & Load up interactive Ruby \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} `\$ gem install sinatra` & Install sinatra gem \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} `\$ gem install twitter` & Install twitter gem \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} `\$ ruby server.rb` & Tell Ruby interpreter to run code. \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} Ctrl+C & Stop server from running. \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Web and HTTP}} \tn % Row 0 \SetRowColor{LightBackground} Server & has IP address, processes requests made by the (client) browser \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} HTTP & protocol enabling communication between clients and servers \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} HTTP Verbs & `GET, POST, PUT, PATCH, DELETE` \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} GET & Request Tweets(data) from Twitter API \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} POST & Submit Tweet(data) to Twitter API \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} https: & scheme \tn % Row Count 14 (+ 1) % Row 6 \SetRowColor{LightBackground} twitter.com & domain \tn % Row Count 15 (+ 1) % Row 7 \SetRowColor{white} \seqsplit{lauren\_n\_roth/status/699996428429561856} & path \tn % Row Count 18 (+ 3) % Row 8 \SetRowColor{LightBackground} Params hash & `params{[}:tweet{]}` \tn % Row Count 19 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Loops}} \tn % Row 0 \SetRowColor{LightBackground} times & `10.times do` \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & `puts "Hello!"` \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & `end` \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} times loop with counter & `10.times do |counter|` \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} & `puts "\#\{counter\}"` \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} & `end` \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} `each ` & `letters = {[}"a", "b", "c"{]}` \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} & `letters.each do |letter|` \tn % Row Count 11 (+ 2) % Row 8 \SetRowColor{LightBackground} & `puts "Letter \#\{letter\}"` \tn % Row Count 12 (+ 1) % Row 9 \SetRowColor{white} & `end` \tn % Row Count 13 (+ 1) % Row 10 \SetRowColor{LightBackground} `map` & `capital\_letters = letters.map do |letter|` \tn % Row Count 15 (+ 2) % Row 11 \SetRowColor{white} & `letter.upcase` \tn % Row Count 16 (+ 1) % Row 12 \SetRowColor{LightBackground} & `end` \tn % Row Count 17 (+ 1) % Row 13 \SetRowColor{white} block style & `letters.each \{ |letter| puts "Upcase \#\{letter.upcase\}!" \}` \tn % Row Count 20 (+ 3) % Row 14 \SetRowColor{LightBackground} elegant map method & `capitals = letters.map \{ |letter| letter.upcase \}` \tn % Row Count 23 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Twitter API}} \tn % Row 0 \SetRowColor{LightBackground} Download files & \seqsplit{bit.ly/dbc-twitter-sinatra} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Sign Up To Use Twitter API & apps.twitter.com \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Create New App & 1. Create new App 2. Create Access Tokens 3. Ensure permissions are read/write \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} Set up Twitter \$client global variable & `require twitter` \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} & `\$client = \seqsplit{Twitter::REST::Client}.new do |config|` \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} & \seqsplit{`config.consumer\_key} = \seqsplit{"YOUR\_CONSUMER\_KEY"} \seqsplit{config.consumer\_secret} = \seqsplit{"YOUR\_CONSUMER\_SECRET"} \seqsplit{config.access\_token} = \seqsplit{"YOUR\_ACCESS\_TOKEN"} \seqsplit{config.access\_token\_secret} = \seqsplit{"YOUR\_ACCESS\_SECRET"`} \tn % Row Count 24 (+ 11) % Row 6 \SetRowColor{LightBackground} & `end` \tn % Row Count 25 (+ 1) % Row 7 \SetRowColor{white} Get user timeline & \seqsplit{`\$client.user\_timeline`} \tn % Row Count 27 (+ 2) % Row 8 \SetRowColor{LightBackground} Send tweet & \seqsplit{`\$client.update("omg} I am tweeting from the command line. So cool!")` \tn % Row Count 31 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}