• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    Ruby
  • License
    Other
  • Created over 10 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Source code for the book Effective Ruby by Peter J. Jones.

Effective Ruby Source Code

Source code for the book Effective Ruby by Peter J. Jones [].

Effective Ruby

Introduction

Virtually all of the code from the book is implemented as unit tests using MiniTest. I used a makefile and some scripts to convert the book from Markdown to the format used by my publisher, Addison-Wesley. During this process all of the tests are run and snippets of code are automatically extracted from the tests and inserted into the final document.

Running the Tests

If you just want to run the tests against your currently installed version of Ruby:

bundle install && rake test

On the other hand, if you have rbenv [] installed and want to test against all the versions listed in the ruby-versions.txt file:

./runtests.sh

That script will install all of the necessary Ruby versions and then test against each one of them.

Issues and Pull Requests

There are several reasons you might want to open an issue:

  • You get the tests to pass on a version or implementation of Ruby not listed below. In that case, I'll update this file and reference you and the issue.

  • You get the tests to fail. Please provide as much detail in the issue description. Worst case I'll update this file and reference the issue and any workarounds.

  • You don't like one of my examples or disagree with the approach taken. Write a good issue description, include an alternate approach, and if I like it I'll reference it in this file.

Please do not submit pull requests. If there ever happens to be a new edition of the book then I don't want to have to track down every contributor in order to sign a release. I'm lazy. Plus, come on, this is just example code.

Directory/Chapter Layout

The source code in this repository includes all of the code shown in the book Effective Ruby along with the snippets of code used to produce the IRB sessions. It also includes several source code files that did not appear in the book. First, let's take a look at the directories that correspond to chapters in the book.

  • ruby: Chapter 1: Accustoming Yourself to Ruby.

  • oop: Chapter 2: Classes, Objects, and Modules.

  • collections: Chapter 3: Collections.

  • exceptions: Chapter 4: Exceptions.

  • meta: Chapter 5: Metaprogramming.

  • testing: Chapter 6: Testing.

  • tools: Chapter 7: Tools and Libraries.

  • performance: Chapter 8: Memory Management and Performance.

The remaining directories contain the following:

  • assumptions: General tests created to ensure that statements given in the book are accurate.

  • benchmarks: Various benchmarks to compare the performance of core classes or Ruby programming techniques.

  • coverage: Example project for the test code coverage metrics given in chapter 6.

  • data: CSV files used by the tests along with profiling output used in chapter 8.

  • fuzz: Example of using FuzzBert from chapter 6.

  • irb: All of the scripts used to generate the IRB output in the book, organized by chapter.

  • lib: Code used in the book for both examples and also by the IRB scripts.

Ruby Version

Unless otherwise noted, all of the code in this repository works with the following Ruby versions:

  • 1.9.3 (Official Ruby)
  • 2.0.0 (Official Ruby)
  • 2.1.0 (Official Ruby)
  • 2.1.1 (Official Ruby)
  • 2.1.2 (Official Ruby)

Where:

Official Ruby: ~ The original and official implementation of the Ruby interpreter and language by the Ruby Core team (MRI).

Files that only work with a specific version of Ruby will have a version specifier in their name. For example:

patching_2_1_test.rb

This file will only work with Ruby 2.1 or greater. The Rakefile ensures that files are omitted from testing if the version of the Ruby interpreter isn't appropriate.

Contacting the Author

If you want to contact the author about the source code in this repository please look at the Issues and Pull Requests section above. For non-source code related topics, you can reach the author through his website.

The author tweets Ruby tips at @EffectiveRuby and personal junk at @contextualdev.

More Repositories

1

xmonadrc

My XMonad configuration
Haskell
57
star
2

nix-hs

Haskell + nixpkgs = nix-hs
Nix
23
star
3

byline

Haskell library for creating command-line interfaces (colors, menus, etc.)
Haskell
22
star
4

minidox-case

A 3D-printed case for the Minidox keyboard
OpenSCAD
15
star
5

oled-display

Display a Pomodoro timer on an OLED display via org-clock.
C
15
star
6

bufshow

A simple presentation tool for Emacs
Emacs Lisp
14
star
7

playlists

Library and executable for working with playlist files.
Haskell
12
star
8

themoviedb

Simple Haskell library that provides functions for retrieving movie metadata from TheMovieDB
Haskell
10
star
9

tilde

Peter's NixOS Account
Nix
9
star
10

phoebe

A collection of NixOS modules that add features to the ones in nixpkgs.
Nix
9
star
11

eldoro

A pomodoro timer/tracker that works with org-mode.
Emacs Lisp
9
star
12

openid-connect

An OpenID Connect library that does all the heavy lifting for you
Haskell
9
star
13

pdf-fdf

Library and command line tool for generating FDFs
Ruby
8
star
14

hlwmrc

Peter's herbstluftwm config
Shell
5
star
15

bitlbee-el

Help get Bitlbee (http://www.bitlbee.org) up and running.
Emacs Lisp
4
star
16

passmm

An Emacs minor mode for pass (Password Store).
Emacs Lisp
4
star
17

addy

A full-featured library for parsing, validating, and rendering email addresses
Haskell
4
star
18

nix-utils

A collection personal packages and utilities for NixOS
Nix
4
star
19

cassava-streams

io-streams interface for the cassava CSV library.
Haskell
4
star
20

nixpkgs-jlink

nixpkgs overlay for SEGGER J-Link
Nix
3
star
21

ivory-tower-mynewt

A Tower backend for Apache Mynewt
Haskell
3
star
22

emacsrc

My Emacs configuration files
Emacs Lisp
3
star
23

hakyll-heist

Support for Heist templates in Hakyll generated sites
Haskell
3
star
24

exwm-nw

Named Workspaces for EXWM
Emacs Lisp
3
star
25

ido-select-window

Emacs package to select a window using ido and buffer names.
Emacs Lisp
3
star
26

vimeta

Frontend for video metadata tagging tools
Haskell
2
star
27

elisp

Various Emacs Lisp files/modes
Emacs Lisp
2
star
28

grunt

Keep your OS config files in Git, and apply them with GNU Make
Shell
2
star
29

org-clock-fifo

A global minor mode for Emacs that writes org-clock status to a FIFO
Emacs Lisp
1
star
30

ael

Average Employment Length
Ruby
1
star
31

thetvdb

Simple Haskell library that provides functions for retrieving TV series metadata from TheTVDB.
Haskell
1
star
32

mock-httpd

A HTTP server for testing HTTP clients
Haskell
1
star
33

encryption-utils

Utilities and Tutorials for Encryption Tasks
Shell
1
star
34

exwm-wb

Control browsers under EXWM
Emacs Lisp
1
star
35

ghc-ios-util

Utilities and Scripts for Haskell iOS Development
Shell
1
star
36

devalot-hakyll

Hakyll extensions for Devalot.com
Haskell
1
star
37

ivy-exwm

Ivy completion for EXWM
Emacs Lisp
1
star
38

personal-webhooks

Trigger personal scripts from incoming HTTP requests
Haskell
1
star
39

unix-starter-kit

Configuration files for Unix tools (e.g. Emacs, zsh, etc.) for people new to Unix-like systems.
Emacs Lisp
1
star
40

backup-scripts

Peter's Backup Scripts
Nix
1
star