Programming Ruby 3.3: The Pragmatic Programmers' Guide

Programming Ruby 3.3: The Pragmatic Programmers' Guide

Programming Ruby 3.3: The Pragmatic Programmers' Guide
Автор: Rappin Noel
Дата выхода: 2013
Издательство: The Pragmatic Programmers, LLC.
Количество страниц: 1215
Размер файла: 3.6 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Preface....17

Why Ruby?....18

A Word about Ruby Versions....19

Notation Conventions....20

Road Map....23

Resources....25

Acknowledgments....26

Part I. Facets of Ruby....28

1. Getting Started....29

Installing Ruby....30

Installing Ruby for Windows....38

Running Ruby....45

Creating Ruby Programs....48

Getting More Information about Ruby....50

What’s Next....52

2. Ruby.new....53

Ruby Is an Object-Oriented Language....55

Some Basic Ruby....59

Arrays and Hashes....65

Symbols....68

Control Structures....70

Regular Expressions....73

Blocks....76

Reading and ‘Riting....80

Command-Line Arguments....81

Commenting Ruby....82

What’s Next....83

3. Classes, Objects, and Variables....84

Defining Classes....85

Objects and Attributes....91

Classes Working with Other Classes....100

Specifying Access Control....105

Variables....111

Reopening Classes....114

What’s Next....117

4. Collections, Blocks, and Iterators....118

Arrays....119

Hashes....124

Digging....127

Word Frequency: Using Hashes and Arrays....128

Blocks and Enumeration....135

What’s Next....170

5. More about Methods....171

Defining a Method....172

Calling a Method....185

What’s Next....195

6. Sharing Functionality: Inheritance, Modules, and Mixins....196

Inheritance and Messages....198

Modules....205

Inheritance, Mixins, and Design....222

What’s Next....225

7. Basic Types: Numbers, Strings, and Ranges....226

Numbers....227

Strings....232

Ranges....241

What’s Next....246

8. Regular Expressions....247

What Regular Expressions Let You Do....248

Creating and Using Regular Expressions....249

Regular Expression Patterns....253

Regular Expression Syntax....258

What’s Next....271

9. Expressions....272

Operator Expressions....274

Command Expressions....278

Assignment....280

Conditional Execution....287

Loops and Iterators....299

Pattern Matching....309

What’s Next....322

10. Exceptions....323

The Exception Class....325

Handling Exceptions....327

Raising Exceptions....333

Using Catch and Throw....336

What’s Next....339

11. Basic Input and Output....340

What Is an I/O Object?....341

Opening and Closing Files....342

Reading and Writing Files....344

Talking to Networks....352

What’s Next....354

12. Threads, Fibers, and Ractors....355

Multithreading with Threads....358

Running Multiple External Processes....372

Creating Fibers....378

Understanding Ractors....382

What’s Next....391

13. Testing Ruby Code....392

Why Unit Test?....393

Testing with Minitest....394

Structuring Tests....402

Creating Mock Objects in Minitest....406

Organizing and Running Tests....410

Testing with RSpec....414

What’s Next....429

Part II. Ruby in Its Setting....431

14. Ruby from the Command Line....432

Calling the Ruby Command....433

Ruby Command-Line Options....437

Making Your Code an Executable Program....443

Processing Command-Line Arguments to Your Code....445

Accessing Environment Variables....454

Where Ruby Finds Its Libraries....458

Using the Rake Build Tool....460

The Build Environment....467

What’s Next....468

15. Ruby Gems....469

Installing and Managing Gems....470

Using Bundler to Manage Groups of Gems....475

Writing and Packaging Your Own Code into Gems....489

Organizing Your Source Code....497

Distributing and Installing Your Code....508

What’s Next....513

16. Interactive Ruby....514

Using irb....516

Navigating irb....522

Configuring irb....527

What’s Next....536

17. Debugging Ruby....537

Printing Things....538

The Ruby Debugger....540

Pry....547

Debugging Performance Issues with Benchmark....552

What’s Next....555

18. Typed Ruby....556

What’s a Type?....558

Official Ruby Typing with RBS....561

Ruby Typing with Sorbet....572

What’s Next....579

19. Documenting Ruby....580

Documenting with RDoc....581

Adding RDoc to Ruby Code....585

Running RDoc....592

Documenting with YARD....595

What’s Next....600

Part III. Ruby Crystallized....602

20. Ruby and the Web....603

Ruby’s Web Utilities....605

Templating with ERB....609

Serving Ruby Code to the Web....614

Ruby in the Browser with Web Assembly....629

What’s Next....632

21. Ruby Style....633

Written Ruby Style....635

Using RuboCop....644

Using Standard....653

Ruby Style in the Large....655

Duck Typing....658

What’s Next....681

22. The Ruby Object Model and Metaprogramming....682

Understanding Objects and Classes....684

Defining Singleton Methods....689

Inheritance and Visibility....699

Modules and Mixins....701

Metaprogramming Class-Level Macros....712

Using instance_eval and class_eval....726

Using Hook Methods....732

A Metaprogramming Example....742

Top-Level Execution Environment....746

What’s Next....748

23. Reflection and Object Space....749

Looking at Objects....750

Looking at Classes....754

Calling Methods Dynamically....757

System Hooks....761

Tracing Your Program’s Execution....765

Behind the Curtain: The Ruby VM....769

Marshaling and Distributed Ruby....771

What’s Next....779

Part IV. Ruby Language Reference....781

24. Language Reference: Literal Types and Expressions....782

Source Layout....783

Ruby Literals....789

Regular Expressions....802

Names....813

Values, Variables, and Constants....817

Expressions, Conditionals, and Loops....830

25. Language Reference: Objects and Classes....847

Method Definition....848

Invoking a Method....856

Aliasing....865

Defining Classes....867

Defining Modules....871

Access Control....874

Blocks, Closures, and Proc Objects....875

Exceptions....882

Catch and Throw....885

Typed Ruby....886

Part V. Ruby Library Reference....897

26. Library Reference: Core Data Types....898

Dates and Times....900

Math....913

Numbers....915

Random and SecureRandom....928

Regexp....931

Strings....951

Symbols....971

27. Library Reference: Ruby’s Object Model....973

BasicObject....975

Class....980

Comparable....982

Kernel....984

Method....1003

Module....1006

Object....1015

28. Library Reference: Enumerators and Containers....1021

Array....1023

Enumerable....1037

Enumerator....1051

Hash....1055

Set....1065

29. Library Reference: Input, Output, Files, and Formats....1070

CSV....1072

Dir....1076

File....1082

FileUtils....1092

IO....1097

JSON....1114

Pathname....1117

StringIO....1119

Tempfile....1121

URI....1123

YAML....1127

30. Library Reference: Ruby on Ruby....1132

Benchmark....1134

Data....1136

Delegator and SimpleDelegator....1138

Logger....1141

ObjectSpace....1144

Observable....1146

OpenStruct....1149

PP....1150

Prism....1151

Ripper....1155

Singleton....1159

Struct....1160

Unbound Method....1163

Part VI. Appendixes....1165

A1. Troubleshooting Ruby....1166

Common Issues....1167

Debugging Tips....1172

A2. I Can’t Look It Up!....1174

A3. Command-Line Basics....1180

The Command Prompt....1181

Folders, Directories, and Navigation....1182

A4. Ruby Runtimes....1185

Just-in-Time Compilers....1186

TruffleRuby....1190

JRuby....1192

mRuby....1194

Other Runtimes....1195

A5. Ruby Changes....1197

Version 2.0....1198

Version 2.1....1199

Version 2.2....1200

Version 2.3....1201

Version 2.4....1202

Version 2.5....1203

Version 2.6....1204

Version 2.7....1205

Version 3.0....1206

Version 3.1....1207

Version 3.2....1208

Version 3.3....1209

Ruby is one of the most important programming languages in use for web development. It powers the Rails framework, which is the backing of some of the most important sites on the web. The Pickaxe Book, named for the tool on the cover, is the definitive reference on Ruby, a highly-regarded, fully object-oriented programming language. This updated edition is a comprehensive reference on the language itself, with a tutorial on the most important features of Ruby - including pattern matching and Ractors - and describes the language through Ruby 3.3.

Would you like to go from first idea to working code much, much faster? Do you currently spend more time satisfying the compiler instead of your clients or end users? Are you frustrated with demanding languages that seem to get in your way instead of helping you get the work done? Are you using Rails and want to dig deeper into the underlying Ruby language? If so, then we've got a language and book for you!

Ruby is a fully object-oriented language. The combination of the power of a pure object-oriented language with the convenience of a scripting language makes Ruby a favorite tool of programmers that want to get things done quickly and cleanly.

This comprehensive reference manual for Ruby includes a description of the most important standard library modules, built-in classes, and modules. It also includes all the new and changed syntax and semantics introduced through Ruby 3.3, including pattern matching and Ractors, and describes the language through Ruby 3.3.

What You Need:

  • This book assumes you have a basic understanding of object-oriented programming.
  • In general, Ruby programmers tend to favor the the command line for running their code, and they tend to use text editors rather than IDEs.
  • Ruby runs on Windows, Linux, and MacOS.

Похожее:

Список отзывов:

Нет отзывов к книге.