Home > Store

Learn Enough Ruby to Be Dangerous: Write Programs, Publish Gems, and Develop Sinatra Web Apps with Ruby (LiveLessons)

Learn Enough Ruby to Be Dangerous: Write Programs, Publish Gems, and Develop Sinatra Web Apps with Ruby (LiveLessons)

Your browser doesn't support playback of this video. Please download the file to view it.

Online Video

Register your product to gain access to bonus material or receive a coupon.

Description

  • Copyright 2022
  • Edition: 1st
  • Online Video
  • ISBN-10: 0-13-784440-9
  • ISBN-13: 978-0-13-784440-1

7 Hours of Video Instruction

In Learn Enough Ruby to Be Dangerous: Write Programs, Publish Gems, and Develop Sinatra Web Apps with Ruby, renowned instructor Michael Hartl teaches the concepts, skills, and approaches you need to be professionally productive with Ruby for both general-purpose programming and beginning web app development.

Overview

Programmers love Ruby for its elegance, power, and flexibility: that's why it was chosen for the Ruby on Rails framework that launched websites from Shopify to Coinbase. You'll love Ruby too, but you don't need to learn "everything" about it, just how to use it efficiently to solve real problems. Best-selling author and leading Rails developer Michael Hartl gets you started writing practical and modern Ruby programs as fast as possible, with a focus on the real tools used every day by software developers. You'll learn how to use Ruby interactively, write shell scripts in Ruby, and use Ruby to make simple dynamic web applications.

Even if you're new to programming, Hartl helps you quickly build technical sophistication as you gain a solid understanding of object-oriented and functional programming, develop and publish a self-contained Ruby package (a gem), and use your gem to build and deploy a dynamic web app with the Sinatra framework. Focused exercises help you internalize what matters, without wasting time on details pros don't care about. Soon, it'll be like you were born knowing this stuff--and you'll be suddenly, seriously dangerous.

About the Instructor

Michael Hartl is the creator of the Ruby on Rails Tutorial, one of the leading introductions to web development, and is cofounder and principal author at Learn Enough. Previously, he was a physics instructor at the California Institute of Technology (Caltech), where he received a Lifetime Achievement Award for Excellence in Teaching. He is a graduate of Harvard College, has a PhD in Physics from Caltech, and is an alumnus of the Y Combinator entrepreneur program.

Skill Level

  • Beginner to intermediate

Learn How To

  • Create a simple "hello, world" program using several different techniques
  • Deploy a simple dynamic Ruby application to the web
  • Use strings, arrays, and other native objects
  • Define functions
  • Use Ruby for functional programming
  • Utilize test-driven development and publish a Ruby gem
  • Write a shell script
  • Develop a full Ruby web application for detecting palindromes

Who Should Take This Course

  • New and experienced developers looking for a practical introduction to Ruby. The course can also serve as a prerequisite for the popular Ruby on Rails Tutorial or as a natural follow-up to it.

Course Requirements

  • The only prerequisites are a familiarity with basic developer tools (command line, text editor, and Git) and beginning HTML
  • Some programming experience is useful but is not required

Lesson Descriptions

Lesson 1: Hello World!
Lesson 1 begins at the beginning by having you create four simple "hello, world" programs using several different techniques. The main purpose of the "hello, world" is to make sure your system is correctly configured to execute the simple program that prints the string "hello, world!" to the screen. You start by writing a series of programs to display a greeting at a command line terminal, first in a REPL called irb (interactive Ruby), then from a file, and then from a shell script. Finally, you write and deploy a simple proof-of-concept web application using the Sinatra web framework.

Lesson 2: Strings
Lesson 2 covers strings, probably the most important data structure on the web since web pages ultimately consist of strings and characters sent to and from the browser. Many other kinds of programs require string manipulation as well. Thus, strings are a great place to start your Ruby programming journey. The lesson starts with what strings are and how to create them, including both single- and double-quoted strings. You then learn how to join, or concatenate, one string to another. Next, you learn how to print to the screen from the terminal window. As part of this, you see your first examples of Ruby boolean variables and control flow. Finally, you learn how to iterate over strings with for loops, enabling you to access strings one character at a time.

Lesson 3: Arrays
In Lesson 2, you learned that strings can be thought of sequences of characters in a particular order. In Lesson 3, you learn about the array data type, which is the general Ruby container for arbitrary elements in a particular order. You start by explicitly connecting strings and arrays via the string split method, and then you learn about various array methods throughout the rest of the lesson. After learning to split strings, you learn how to access elements in the resulting array, discovering that the same syntax works on strings, further deepening the connection between the two data types. Next, you learn a variety of additional array methods beginning with selecting both single elements and multiple elements at once using array slicing, including the useful range datatype, and a clever technique using range indices to select the last element in an array. Then you learn how to sort arrays, which, if you have ever written a sorting algorithm by hand, you will find Ruby makes ridiculously easy. You also learn how to reverse arrays, a capability you will put to good use later on in the tutorial when learning to detect palindromes. Next, you learn how to add and remove array elements using push and pop, including an introduction to the important shovel operator. You then learn how to undo a string split with an array and join. Finally, you learn how to iterate through arrays using the same kind of for loop covered in Lesson 2, which is valuable preparation for more advanced techniques covered in Lessons 5 and 6.

Lesson 4: Other Native Objects
Now that we have taken a look at strings and arrays, Lesson 4 continues with a tour of some other important Ruby objects, which gives you a chance to learn about math, dates, regular expressions, and hashes. Like most programming languages, Ruby supports a large number of mathematical operations right out of the box, such as addition, subtraction, multiplication, and division. It also includes a math library with more advanced operations such as logarithms and trigonometric functions. You also learn how to deal with times and dates in Ruby, such as getting the year, the day, or the exact time. This gives you your first chance to use the new function, a so-called constructor function, which is the standard Ruby way to create a new object. This lesson includes an introduction to the powerful subject of regular expressions, which are discussed briefly in Learn Enough Developer Tools to be Dangerous in the context of text editors and the grep command. Often called regexes for short, regular expressions are a powerful mini-language for matching patterns in text. You learn how to use regexes to quickly search strings for things like five digits in a row, thereby matching standard United States ZIP codes. The lesson ends with an introduction to hashes in Ruby. You use such objects to create collections of keyvalue pairs, sometimes known as associative arrays, which are like regular arrays but with strings instead of integers as indices. You apply this important object type to write your first substantial Ruby program, a shell script to count the unique words in a text.

Lesson 5: Functions and Blocks
So far in this tutorial, Ruby functions have been mentioned repeatedly, and in Lesson 5 you finally learn to define functions of your own. The resulting ability gives us greater flexibility as programmers and enables powerful techniques like the each method, which is covered in this lesson, and functional programming, which is the subject of Lesson 6. You begin your study of functions in the read-eval-print loop, that is, the REPL, and then you learn how to put your function definitions in a file for use in a simple Sinatra web application. The lesson also covers how to use multiple functions in a row, a technique known as method chaining. Method chaining is used to make a first definition of a palindrome function to see whether a string is the same forward and backward. The lesson ends with a discussion of the each method of iterating through arrays, which often provides a more convenient way of processing array elements than the for loop introduced in Lesson 2. This gives you your first introduction to blocks, a feature Ruby shares with only a few other languages and which are the source of much of Ruby's unusual flexibility and power.

Lesson 6: Functional Programming
Having learned how to define functions and apply them in a couple of different contexts. In Lesson 6, you take your programming to the next level by learning the basics of functional programming, a style of programming that emphasizes, you guessed it, functions. This is a challenging lesson, and you may have to watch it a couple of times to absorb everything, but the rewards are rich indeed. It focuses on the triumvirate of functions commonly used in functional programming, that is, map, select, and reduce. The first of our examples is the map function, which lets you map a function over an array of elements. It is often a powerful alternative to looping. The second function covered is select, which enables you to select your data based on some boolean criterion. For example, you can take an array of integers and select for only numbers evenly divisible by two, giving you a quick way to select only the even numbers in the array. The third function is the mighty reduce, which is exactly the kind of powerful technique that can take lots of examples to really sink in but enables you to write remarkably clean and concise code. Because reduce, and indeed all functional techniques, can be challenging to understand even for experienced developers, it is especially powerful when combined with test-driven development, which is covered in Lesson 8.

Lesson 7: Objects and Classes
In Lesson 7, you learn how to make your very own Ruby objects, which can have both attributes, which are data, and methods, which are functions, attached to them. The way to define objects in Ruby is using the class method, which gives rise to an object constructor function that can be used to create or instantiate a new object called an instance using the new method you first saw in Lesson 4. This gives you the background needed to understand Ruby's object system, which pervades the language. Indeed, it is often said that everything in Ruby is an object. In this lesson you learn the precise technical meaning of this description. You start with a concrete example of a phrase object that knows whether or not the phrase is a palindrome. You then add a translated phrase object that overrides the main palindrome method and substitutes a translated phrase instead. These examples enable you to understand inheritance and derived classes, which are key ideals in object-oriented programming. The lesson even discusses the powerful, even dangerous, practice of modifying native Ruby objects. This enables us to modify the string class itself, giving every string the capability to tell whether or not it is a palindrome. Finally, we learn about Ruby modules, also called mixins. Ruby modules give us a way to factor out common functionality and then mix it into multiple classes, which is a great way to avoid duplication and reuse code.

Lesson 8: Testing and Test-Driven Development
Although rarely covered in introductory programming tutorials, automated testing is one of the most important subjects in modern software development. Accordingly, Lesson 8 gives you an introduction to testing in Ruby, including a first look at test-driven development, or TDD. Test-driven development came up briefly in Lesson 6, where we promised that you would use testing techniques to add an important capability to finding palindromes, namely being able to detect complicated palindromes such as, "A man a plan a canal--Panama!" or "Madam, I'm Adam". This lesson fulfills that promise. You start by setting up our system for testing using the minitest framework. The strategy for testing the current palindrome code and extending it to more complicated phrases is as follows. One, set up your system for automating testing. Two, write automated tests for the existing palindrome functionality. Three, write a failing test for the enhanced palindrome detector known as red. This is the first step in the TDD cycle known as red, green, refactor. Four, write possibly ugly code to get the test passing, also known as green, which is the second step in red, green, refactor. Five, refactor the code, which involves changing its form without changing its function. Because the code should accomplish the same results the entire time, the test suite should remain green even after refactoring, thereby completing the red, green, refactor cycle. As it turns out, learning how to write Ruby tests also gives you a chance to learn how to create and use self-contained software packages called Ruby gems, another valuable skill for longer Ruby programming.

Lesson 9: Shell Scripts
In Lesson 8 you build on the foundation laid in the previous lessons and write three shell scripts of increasing sophistication. Although web development is probably the most common application of Ruby programming nowadays, shell scripting is Ruby's native habitat, so it is a task at which Ruby understandably excels. Indeed, readers who have studied the analogous material in the context of JavaScript may be impressed at how much more elegant and polished the Ruby versions are. In the first two programs, you take the Ruby gem developed in Lesson 8 and put it to work detecting palindromes drawn from two different sources: a file and the web. In the process, you learn how to read and write from files with Ruby and also how to read a live web URL. (This latter example has especially personal meaning to the author, as he distinctly remembers the first time he wrote an automated program to read and process text from the web, which at the time seemed truly miraculous.) Finally, you write a real-life utility program adapted from one the author once wrote for himself. It includes an introduction to manipulation of the document object model, or DOM, in the context outside of a web browser. This is the sort of thing you might expect from a browser-centric language like JavaScript, but it turns out you can do it with Ruby as well.

Lesson 10: A Live Web Application
As a final application of your newfound Ruby powers, in this final lesson you build a dynamic web application. The app puts the custom Ruby gem developed in Lesson 8 to good use through the development of a web-based palindrome detector. Along the way, you learn how to create dynamic content using embedded Ruby, or ERB. Detecting palindromes from the web requires using a back-end web application to handle form submission, and our tool of choice is Sinatra, the micro-framework you met in Lesson 1 and applied further in Lesson 5. Although simple, Sinatra is not a toy. It is a production-ready web framework used by companies like Stripe, Apple, and Disney. Our palindrome map also features two other pages, home and about, which give you an opportunity to learn how to use a Ruby-based site layout. As part of this, you apply and extend the work in Lesson 8 to write automated tests for your app. As in Lesson 1, your final step is to deploy your palindrome map to the live web. The lesson ends with pointers to further resources for Ruby, Sinatra, and other topics like JavaScript and Ruby on Rails.

About Pearson Video Training

Pearson publishes expert-led video tutorials covering a wide selection of technology topics designed to teach you the skills you need to succeed. These professional and personal technology videos feature world-leading author instructors published by your trusted technology brands: Addison-Wesley, Cisco Press, Pearson IT Certification, Sams, and Que. Topics include: IT Certification, Network Security, Cisco Technology, Programming, Web Development, Mobile Development, and more. Learn more about Pearson Video training at informit.com/video.

Video Lessons are available for download for offline viewing within the streaming format. Look for the green arrow in each lesson.

Sample Content

Table of Contents

Introduction

Lesson 1: Hello World!
Topics
1.1 Introduction to Ruby
1.2 Ruby in a REPL
1.3 Ruby in a file
1.4 Ruby in a shell script
1.5 Ruby in a web browser

Lesson 2: Strings
Topics
2.1 String basics
2.2 Concatenation and interpolation
2.3 Printing
2.4 Attributes, Booleans, and control flow
2.5 Methods
2.6 String iteration

Lesson 3: Arrays
Topics
3.1 Splitting
3.2 Array access
3.3 Array slicing
3.4 More array methods
3.5 Array iteration

Lesson 4: Other Native Objects
Topics
4.1 Math
4.2 Time
4.3 Regular expressions
4.4 Hashes
4.5 Application: Unique words

Lesson 5: Functions and Blocks
Topics
5.1 Function definitions
5.2 Functions in a file
5.3 Method chaining
5.4 Blocks

Lesson 6: Functional Programming
Topics
6.1 Map
6.2 Select
6.3 Reduce

Lesson 7: Objects and Classes
Topics
7.1 Defining classes
7.2 Inheritance
7.3 Derived classes
7.4 Modifying native objects
7.5 Modules

Lesson 8: Testing and Test-Driven Development
Topics
8.1 Testing and Ruby gem setup
8.2 Initial test coverage
8.3 Red
8.4 Green
8.5 Refactor

Lesson 9: Shell Scripts
Topics
9.1 Reading from files
9.2 Reading from URLs
9.3 DOM manipulation at the command line

Lesson 10: A Live Web Application
Topics
10.1 Setup
10.2 Site pages
10.3 Layouts
10.4 Embedded Ruby
10.5 Palindrome detector
10.6 Conclusion

Summary

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020