コース一覧へ戻る
AI035 Professional

Programming Ruby: The Pragmatic Programmers' Guide (Second Edition)

A comprehensive reference and tutorial for the Ruby programming language, covering basic syntax, object-oriented design, advanced features like reflection and threading, and a complete library reference for version 1.8.

4.9
45h
515 受講者
0 いいね
人工知能

コース概要

📚 Content Summary

A comprehensive reference and tutorial for the Ruby programming language, covering basic syntax, object-oriented design, advanced features like reflection and threading, and a complete library reference for version 1.8.

Master the art of elegant and powerful programming with the definitive guide to the Ruby language.

Author: Dave Thomas, Chad Fowler, Andy Hunt

Acknowledgments: Reviewers from the Ruby mailing list, Yukihiro Matsumoto (Matz), Chad Fowler, Kim Wimpsett, and the Pragmatic Programmers community.

🎯 Learning Objectives

  1. Install and configure the Ruby environment using various methods (binary, source, or CVS) and utilize interactive tools like irb and ri.
  2. Apply Ruby’s naming conventions and object-oriented principles to define methods and manage variables.
  3. Manipulate data using basic arrays, hashes, and regular expressions.
  4. Define and implement class hierarchies using single inheritance, super, and mixins.
  5. Control object visibility and data integrity using Access Control (Public, Private, Protected) and Attributes.
  6. Construct robust container classes (e.g., SongList) integrated with Unit Testing.
  7. Implement numeric logic using various bases (hex, octal, binary) and utilize numeric iterators for control flow.
  8. Construct complex strings using interpolation, heredocs, and various delimiter formats.
  9. Apply Ranges as "toggle switches" in conditional logic and as interval testers.
  10. Define and invoke methods using flexible argument lists (splat operator), hash-based "keyword" arguments, and block-to-proc conversions.

🔹 Lesson 1: Ch. 1-2: Foundations and Getting Started with Ruby.new

Overview: This lesson provides a comprehensive introduction to the Ruby ecosystem, covering installation methods from binary distributions to building from source and utilizing source code management. Students will explore the fundamental syntax of Ruby, emphasizing its pure object-oriented nature, naming conventions, and core programming constructs such as containers, control structures, and blocks.

Learning Outcomes:

  • Install and configure the Ruby environment using various methods (binary, source, or CVS) and utilize interactive tools like irb and ri.
  • Apply Ruby’s naming conventions and object-oriented principles to define methods and manage variables.
  • Manipulate data using basic arrays, hashes, and regular expressions.

🔹 Lesson 2: Ch. 3-4: Classes, Objects, Variables, and Containers

Overview: This lesson explores the fundamental mechanics of Ruby’s object-oriented system, focusing on how objects maintain state through inheritance and how the method lookup chain operates. It transitions into practical container implementation using Arrays and Hash-like logic, finalized by a deep dive into Ruby’s unique block architecture—covering iterators, closures, and resource management.

Learning Outcomes:

  • Define and implement class hierarchies using single inheritance, super, and mixins.
  • Control object visibility and data integrity using Access Control (Public, Private, Protected) and Attributes.
  • Construct robust container classes (e.g., SongList) integrated with Unit Testing.

🔹 Lesson 3: Ch. 5: Mastery of Standard Types and Regex

Overview: This lesson provides a deep dive into Ruby’s core scalar types—Numbers, Strings, and Ranges—and transitions into the powerful world of Regular Expressions. Students will learn how Ruby handles numeric overflow automatically, how to manipulate strings through interpolation and delimiters, and how to utilize regular expressions as both functional patterns and object-oriented entities for complex text processing.

Learning Outcomes:

  • Implement numeric logic using various bases (hex, octal, binary) and utilize numeric iterators for control flow.
  • Construct complex strings using interpolation, heredocs, and various delimiter formats.
  • Apply Ranges as "toggle switches" in conditional logic and as interval testers.

🔹 Lesson 4: Ch. 6-7: Method Logic and Expression Control

Overview: This lesson explores the flexible nature of Ruby methods and the power of expression-based programming. Students will master defining methods with variable arguments, integrating blocks dynamically, and utilizing advanced control structures like parallel assignment and pattern-matching case expressions. The content emphasizes that in Ruby, almost everything is an expression that returns a value, enabling concise and readable logic.

Learning Outcomes:

  • Define and invoke methods using flexible argument lists (splat operator), hash-based "keyword" arguments, and block-to-proc conversions.
  • Execute complex logic through parallel/nested assignments and sophisticated boolean expressions.
  • Implement flow control using expression-based conditionals (if, unless, case) and advanced loop modifiers (break, redo, next).

🔹 Lesson 5: Ch. 8-9: Error Handling and Modular Architecture

Overview: This lesson covers robust error management and structural design in Ruby. It explores the exception hierarchy and mechanisms for handling errors (rescue, retry) or controlling flow across scopes (catch, throw). Additionally, it details how Modules facilitate code reuse through namespaces and mixins, the integration of the Enumerable module, and the mechanics of including external files.

Learning Outcomes:

  • Implement resilient error handling using the Exception class hierarchy and non-local control structures.
  • Construct modular codebases using Modules for namespacing and Mixins for cross-class functionality.
  • Apply the Enumerable module to custom classes and resolve method name ambiguities in multi-module environments.

🔹 Lesson 6: Ch. 10-11: I/O Operations and Concurrency

Overview: This lesson covers the fundamentals of Ruby's Input/Output (I/O) system and its concurrency model. Students will learn to manage external resources through IO objects—including files, strings, and network sockets—while exploring multi-threaded programming. The curriculum transitions from basic file manipulation to complex synchronization techniques (Monitors, Queues) and external process management to handle parallel tasks efficiently.

Learning Outcomes:

  • Perform file operations using manual and block-based resource management to ensure data integrity.
  • Process data streams using iterators and the StringIO library for flexible I/O handling.
  • Establish network communication via TCP sockets and higher-level protocols like HTTP.

🔹 Lesson 7: Ch. 12-13: Testing, Debugging, and Optimization

Overview: This lesson provides a comprehensive guide to ensuring code quality and performance in Ruby. It covers the principles of unit testing using the Test::Unit framework, techniques for systematic debugging via the Ruby debugger, and methods for identifying performance bottlenecks through benchmarking and profiling. Students will learn how to structure tests, troubleshoot common logic "gotchas," and optimize code based on empirical data.

Learning Outcomes:

  • Implement automated unit tests using the Test::Unit framework and various assertion types.
  • Diagnose and resolve code defects using the Ruby command-line debugger and common troubleshooting strategies.
  • Analyze code performance using the Benchmark module and the Profiler to identify and fix execution bottlenecks.

🔹 Lesson 8: Ch. 14-16: The Ruby Ecosystem and Workflow

Overview: This lesson explores the operational environment of Ruby, focusing on how programs interact with the command line, manage their execution environment, and utilize interactive tools. Students will also learn to document their code using RDoc and the ri system to create professional-grade, searchable documentation and integrated help systems.

Learning Outcomes:

  • Control Ruby program behavior using command-line arguments, environment variables, and termination methods.
  • Optimize the Interactive Ruby (irb) workflow through custom prompts, tab completion, and subsession management.
  • Generate structured documentation using RDoc markup, hyperlink logic, and modifiers to produce HTML and ri data.

🔹 Lesson 9: Ch. 17-18: Distribution and Web Services

Overview: This lesson covers the essential mechanisms for distributing Ruby code and building web-based applications. It explores the RubyGems system for package management and version control, the implementation of web interfaces via CGI and templating systems, and the integration of distributed systems using SOAP and web services.

Learning Outcomes:

  • Define and package Ruby libraries using the Gem Specification and Rake.
  • Develop dynamic web applications using cgi.rb to handle query parameters, cookies, and sessions.
  • Implement templating systems (ERB, Amrita) to separate application logic from presentation.

🔹 Lesson 10: Ch. 19-20: GUI and Platform Integration

Overview: This lesson covers the construction of graphical user interfaces (GUIs) in Ruby using the Tk library, ranging from basic widget setup to advanced canvas management and scrolling. Additionally, it explores platform-specific integration on Windows, focusing on performance benchmarking for automation and the use of the DL library to interface directly with Windows DLLs.

Learning Outcomes:

  • Construct a functional Ruby Tk application using widgets and various geometry managers (pack, place, grid).
  • Implement interactive elements through event binding and bidirectional scrolling communication.
  • Translate existing Perl/Tk documentation into valid Ruby code and utilize the DL library for low-level Windows API calls.

🔹 Lesson 11: Ch. 21: Extending Ruby (The C API)

Overview: This lesson explores the interface between the Ruby programming language and C, focusing on how to extend Ruby's functionality using C extensions and how to embed the Ruby interpreter into C applications. Students will learn the internal representation of Ruby objects, the protocol for wrapping C data structures, and the tools required to build and configure these extensions.

Learning Outcomes:

  • Understand and manipulate Ruby's VALUE type and immediate objects within a C environment.
  • Implement the multi-step allocation and initialization protocol for custom C-backed Ruby classes.
  • Automate the build process for Ruby extensions using mkmf and extconf.rb.

🔹 Lesson 12: Ch. 22: Comprehensive Language Specification

Overview: This lesson provides a technical deep-dive into the Ruby language specification, covering the fundamental building blocks required for professional development. Students will explore the nuances of Ruby’s basic data types, the strict rules governing variable and constant scope, and the mechanics of expressions and method arguments.

Learning Outcomes:

  • Differentiate between various basic types (Integers, Strings, Symbols) and apply shorthand notations like %w and %q.
  • Manage variable scope and constant visibility across global, class, instance, and local levels.
  • Implement complex control flow using boolean expressions, case statements, and loop modifiers.

🔹 Lesson 13: Ch. 23-24: Duck Typing and Object Invocation

Overview: This lesson explores the mechanics of how Ruby executes code through method invocation, object definitions, and error handling, culminating in the philosophy of "Duck Typing." Students will learn to define flexible interfaces using blocks and Procs and implement robust systems using Ruby's exception and coercion protocols.

Learning Outcomes:

  • Execute complex method lookups and manipulate method behavior using super and alias.
  • Construct structured codebases using class/module definitions and attribute declarations.
  • Implement functional programming patterns using blocks, closures, and Proc objects.

🔹 Lesson 14: Ch. 24-25: Advanced Objects and Security

Overview: This lesson explores the internal architecture of Ruby objects, focusing on the sophisticated relationship between instances, classes, and metaclasses. Students will master dynamic behavior through object-specific classes and metaprogramming techniques while learning to secure applications using Ruby's built-in safe levels and data-tainting mechanisms.

Learning Outcomes:

  • Map the internal pointer structure (klass and super) that governs how classes and objects interact.
  • Implement object-specific behavior using singleton classes and manage state via class instance variables.
  • Apply metaprogramming and object freezing to create robust, immutable, or dynamically generated code.

🔹 Lesson 15: Ch. 26-28: Reflection and the Standard Library

Overview: This module explores Ruby’s powerful introspective capabilities, allowing developers to look inside objects and classes, call methods dynamically, and manage object serialization through Marshaling and YAML. It also provides a comprehensive reference and application guide for the Ruby Standard Library, covering core classes, networking protocols, data storage, and system utilities.

Learning Outcomes:

  • Implement Reflection: Use ObjectSpace, respond_to?, and send to inspect and manipulate objects at runtime.
  • Master Serialization: Apply Marshaling and YAML strategies to persist object states and facilitate Distributed Ruby (DRb) communication.
  • Utilize the Standard Library: Navigate and employ specialized modules for Networking (Net::HTTP), XML/Web (REXML, CGI), and Data Storage (PStore, CSV, SDBM).