The Ruby Workshop
eBook - ePub

The Ruby Workshop

A New, Interactive Approach to Learning Ruby

Akshat Paul, Peter Philips, Dániel Szabó, Cheyne Wallace

Buch teilen
  1. 544 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

The Ruby Workshop

A New, Interactive Approach to Learning Ruby

Akshat Paul, Peter Philips, Dániel Szabó, Cheyne Wallace

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Get to grips with the fundamentals of the Ruby programming language and learn how to build your own applications with the help of real-world examples and hands-on activities

Key Features

  • Learn the fundamentals of Ruby object-oriented programming (OOP)
  • Use the Ruby on Rails framework to build interactive web applications
  • Discover how to quickly build complex programs with fewer lines of code

Book Description

The beauty of Ruby is its readability and expressiveness. Ruby hides away a lot of the complexity of programming, allowing you to work quickly and 'do more' with fewer lines of code. This makes it a great programming language for beginners, but learning any new skill can still be a daunting task. If you want to learn to code using Ruby, but don't know where to start, The Ruby Workshop will help you cut through the noise and make sense of this fun, flexible language.

You'll start by writing and running simple code snippets and Ruby source code files. After learning about strings, numbers, and booleans, you'll see how to store collections of objects with arrays and hashes. You'll then learn how to control the flow of a Ruby program using boolean logic.

The book then delves into OOP and explains inheritance, encapsulation, and polymorphism. Gradually, you'll build your knowledge of advanced concepts by learning how to interact with external APIs, before finally exploring the most popular Ruby framework? Ruby on Rails? and using it for web development.

Throughout this book, you'll work on a series of realistic projects, including simple games, a voting application, and an online blog. By the end of this Ruby book, you'll have the knowledge, skills and confidence to creatively tackle your own ambitious projects with Ruby.

What you will learn

  • Master the syntax and features of Ruby to build useful applications
  • Use common design patterns to simplify code and improve efficiency
  • Understand how to implement object-oriented programming with Ruby
  • Explore ways to fetch, process, and output data
  • Work with public APIs and create reusable RubyGems
  • Debug code to troubleshoot application behavior
  • Create interactive web applications with Ruby on Rails

Who this book is for

The Ruby Workshop is designed for anyone who is new to Ruby and wants a practical introduction to the language. Whether you're completely new to programming, or have experience in another language and want to broaden your skillset, this book will quickly get you up and running.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist The Ruby Workshop als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu The Ruby Workshop von Akshat Paul, Peter Philips, Dániel Szabó, Cheyne Wallace im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Ciencia de la computación & Programación de código abierto. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

1. Writing and Running Ruby Programs

Overview
By the end of this chapter, you will be able to use the Interactive Ruby Shell (IRB) to write Ruby programs; execute Ruby code with a Ruby interpreter using Ruby (.rb) files; implement variables, literals, and constants in Ruby programs; use standard data types, such as numbers, Booleans, and strings, in Ruby programs; execute basic arithmetic operations on integer and floating-point numbers, implement string concatenation and interpolation in Ruby programs.
This chapter introduces the basics of Ruby and serves as a firm foundation to build the complex code that you will encounter later in the book.

Introduction

Ruby is a dynamic, interpreted, object-oriented programming language developed by Yukihiro ("Matz") Matsumoto at some point in the mid-1990s, with its first stable release in 1995. According to the creator of Ruby, it is highly influenced by Perl, Smalltalk, Ada, and Lisp. The influence of these languages on Ruby allows it to embrace various programming paradigms, such as functional, object-oriented, and imperative, with dynamic typing (referred to as duck typing in popular culture) and automatic memory management.
Being an interpreted scripting language, Ruby has the ability to make system calls directly, and has a long list of useful string operations where variable declaration and variable type are not required. Ruby wholly embraces object-oriented programming because everything in Ruby is an object. Ruby has a long list of keywords that make many operations a piece of cake. This means you can do more with less code.
Whether you are a newbie to the world of programming, or an experienced developer in other languages who is tired of the compilation processes, extra declarations, and the keywords of other languages, Ruby will be a revelation from the point of view of your productivity.
With all these characteristics, Ruby gives developers an enriching experience, making programming productive and fun. In addition to Ruby being a fantastic programming language, the Ruby community is also very friendly and supportive.

Key Features of Ruby

A number of key features of the Ruby language make it really unique in terms of working with it. It has very neatly assimilated the best features of many programming languages. Here are a few features of Ruby that make it a delight to program with:
  • Object-oriented
  • Interpreted language
  • Duck typing and dynamic typing
  • Multi-paradigm language
  • Reflection
  • Metaprogramming
    Figure 1.1: Key features of Ruby
Figure 1.1: Key features of Ruby

Object-Oriented

Ruby is thoroughly object-oriented, and objects are the basic building block of a Ruby program. Every value in Ruby is an object, even data types such as strings, numbers, and Booleans: everything is an object. This means that every object is part of a class that gives access to a wide range of methods to do incredible things. Each class is also an object in Ruby. Here's an example:
class Fruit
#code
end
The preceding code defines the Fruit class. The following code shows that two new objects, fruit1 and fruit2, are derived from the Fruit class:
fruit1 = Fruit.new
fruit2 = Fruit.new

Interpreted Language

Ruby is an interpreted language, meaning that it's ready to run the program as soon as you finish typing. Unlike programming languages such as C++, Java, and Objective-C, which require code to be compiled before running, this is not the case with Ruby. Look at this example:
print "Hello World"
This code will immediately print Hello World, as follows:
Hello World

Duck Typing and Dynamic Typing

Dynamic typing means a variable can refer to objects of various types when the program is executed. There is no type checking in Ruby. Duck typing is a principle that denotes that an object is based on the value assigned to it rather than the type of variable. The underlying rule here is: "If it walks like a duck and quacks like a duck, then it must be a duck." Here's an example:
x= [:a, :b, :c]
x.map(&:to_s) # => ['a', 'b', 'c']
The preceding example illustrates how the x variable responds to map and returns the expected object. This means that the x variable here is considered an array.

Multi-paradigm Language

While languages are focused on one type of programming paradigm, besides being object-oriented, Ruby also allows procedural and functional styles of programming. Th...

Inhaltsverzeichnis