Preface

About

This section briefly introduces the coverage of this book, the technical skills you'll need to get started, and the hardware and software requirements required to complete all of the included activities and exercises.

About the Book

You already know you want to learn Ruby, and the smarter way to learn Ruby 2.6 is to learn by doing. The Ruby Workshop focuses on building up your practical skills so that you can kick-start your career as a developer and rapidly prototype applications. You'll learn from real examples that lead to real results.

Throughout The Ruby Workshop, you'll take an engaging step-by-step approach to understanding the Ruby language. You won't have to sit through any unnecessary theory. If you're short on time you can jump into a single exercise each day or spend an entire weekend learning about metaprogramming. It's your choice. Learning on your terms, you'll build up and reinforce key skills in a way that feels rewarding.

Every physical copy of The Ruby Workshop unlocks access to the interactive edition. With videos detailing all exercises and activities, you'll always have a guided solution. You can also benchmark yourself against assessments, track progress, and receive content updates. You'll even earn a secure credential that you can share and verify online upon completion. It's a premium learning experience that's included with your printed copy. To redeem, follow the instructions located at the start of your Ruby book.

Fast-paced and direct, The Ruby Workshop is the ideal companion for Ruby beginners. You'll build and iterate on your Ruby code like a software developer, learning along the way. This process means that you'll find that your new skills stick, embedded as best practice. A solid foundation for the years ahead.

About the Chapters

Chapter 1, Writing and Running Ruby Programs, introduces you to writing and running simple snippets interactively as well as writing and running Ruby source code files.

Chapter 2, Ruby Data types and Operations, will teach you how to work with more complex data types such as arrays and hashes.

Chapter 3, Program Flow, informs you about the different options for controlling how a Ruby program flows: where it branches based on Boolean logic, where it switches tracks based on different cases, and where it circles back on itself to do repetitive work.

Chapter 4, Ruby Methods, builds your understanding of how to construct your own methods and master the concise and elegant syntax that Ruby offers for doing so.

Chapter 5, Object-Oriented Programming with Ruby, familiarizes you with Object-Oriented (OO) programming concepts with Ruby. You will learn how to organize code in a way that sets us up to write larger and more complex applications. We'll also begin looking at a common practice known as Test-Driven Development (TDD), which helps us build better code by getting us to think about our tests first.

Chapter 6, Modules and Mixins, will let you dive deeper into Ruby and OO programming concepts and learn about inheritance, encapsulation, and polymorphism. We will implement these using powerful Ruby language features known as modules and mixins. These will allow us to organize code and teach us deeper concepts of the Ruby object model.

Chapter 7, Introduction to Ruby Gems, focuses on importing data from external sources, processing it using our application and outputting the data in human-readable formats. We'll dive into Ruby's excellent package management system, RubyGems, how to read and write files to the filesystem, and finally how to neatly encapsulate our newly learned service-based code with service classes.

Chapter 8, Debugging with Ruby, instructs you on fundamental logging and debugging concepts and how we debug with Ruby. We'll cover different methods for different purposes and learn real-world techniques that can save you time and effort when it comes to solving problems in both development and production.

Chapter 9, Ruby Beyond the Basics I, teaches you about techniques and concepts such as blocks, procs, and lambdas. We will also learn about a very powerful concept of Ruby called metaprogramming, which is essentially code that writes code.

Chapter 10, Ruby Beyond the Basics II, teaches you how to interact with external APIs. Our code will consume a public API and parse the response. We will then create a reusable module out of this Ruby code and publish it as a Ruby gem.

Chapter 11, Introduction to Ruby on Rails I, introduces you to the most popular Ruby framework, Ruby on Rails. We will learn about the Model-View-Controller (MVC) architecture and how to organize code in Ruby on Rails. When learning about the MVC architecture, we'll see how to keep a fat model and a thin controller. Lastly, we will create a simple Create, Read, Update, and Delete (CRUD) web application with Ruby on Rails.

Chapter 12, Introduction to Ruby on Rails II, continues to build our Rails application and you will learn about REST principles and other fundamental concepts of Ruby on Rails such as routing, the asset pipeline, and ORM (Object Relational Mapping) with ActiveRecord. Finally, we will deploy our Rails application on the server with Heroku.

Conventions

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We use puts to print a string".

Words that you see on the screen, for example, in menus or dialog boxes, also appear in the text like this: "Both of them are inherited by the Integer class"

A block of code is set as follows:

[1,2,3].each do |i|

  puts "My item: #{i}"

end

New terms and important words are shown like this: "With metaprogramming, you can write methods and classes at runtime, which helps us to maintain a Don't Repeat Yourself (DRY) and maintainable code base"

Long code snippets are truncated and the corresponding names of the code files on GitHub are placed at the top of the truncated code. The permalinks to the entire code are placed below the code snippet. It should look as follows:

inheritancewithmodulemethods.rb 

1  module Address

2    attr_accessor :address_line1, :address_line2, :city, :state,:postal_code, :country  

Before You Begin

Each great journey begins with a humble step. Our upcoming adventure with Ruby programming is no exception. Before we can do awesome things using Ruby, we need to be prepared with a productive environment. In this small note, we shall see how to do that.

Installing Ruby 2.6

All code in this book is Ruby 2.x-compatible. However, we have specifically used Ruby 2.6 in our lab environment for all of the book content. We recommend using Ruby 2.6 to avoid any issues completing the chapter.

Please note that the bundler gem, which is used in various chapters of the book, is included within Ruby 2.6, but earlier versions of Ruby will require a manual install by simply running the following code:

gem install bundler

gem install rails

You can use any editor of your choosing to work with Ruby. However, our editor of choice is Visual Studio Code (https://packt.live/35KD2Ek) combined with the Ruby language extension (https://packt.live/33K0Jui).

For Ruby on Rails, you can simply install the extension for Rails on the Visual Studio Code Editor interface. Make sure you have installed all gems using the bundler so that the enabled extension works.

Installing the Code Bundle

Download the code and relevant files from GitHub at https://packt.live/2BowSvw.

Either download the .zip file package or git clone the repository with:

git clone [email protected]:PacktWorkshops/The-Ruby-Workshop.git

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.71.115