• Stars
    star
    282
  • Rank 146,549 (Top 3 %)
  • Language
    Ruby
  • Created over 11 years ago
  • Updated almost 8 years ago

Reviews

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

Repository Details

The code from Russ Olsen's book Design Patterns in Ruby (http://goo.gl/OKPQw)
design_patterns_in_ruby_code
============================

The code from Russ Olsen's book Design Patterns in Ruby (http://goo.gl/OKPQw)

I've updated the code so that it runs with Ruby 2.2.1
but do keep in mind that some of this code is now nine years
old: Thinking and coding styles do change.

The repo is organized by chapter, one subdirectory per chapter.
In each subdirectory you will find Ruby files with names like
ex1_report.rb or ex15_subclass_test.rb or ex13_account_demo.rb.

The files are numbered to roughly follow the order that the
code appears in the book. For example, chap01/ex3_vehicle.rb
appears in the book before chap01/ex8_delegate.rb.

The files whose names end with β€œdemo” are a bit special.
These guys contain the code for the fragmentary, inline examples
(as opposed to full classes) that are sprinkled throughout the 
book – take a look at the code on page 6. These β€œdemo” files
actually make use of a couple of utility methods found in the
"example.rb" in the root code directory.

The problem I had with fragmentary examples was that I wanted to
be sure that the code actually worked, and that the output
that I claimed the code produced actually came out of the code,
no small feat when you are dealing with more than 100 separate 
examples. The solution that I came up with was to wrap each
little example in a call to a method (defined in example.rb)
 called example:

    example %q{
    my_car = Car.new
    my_car.drive(200)
    }

Look closely at the code above and you will see that the 
example code gets passed to the example method as a string.
The example method does two things with that string: first
it prints it out (so that I could snag the code for inclusion
in the book) and then executes it (so that I could snag the
output for inclusion in the book). Ah the wonders of Ruby!

Finally, there are a couple of examples in the later parts
of the book which just didn’t fit into the ex##_*.rb naming
scheme, but these should be pretty self explanatory.

If you have any questions or comments, just email me at
[email protected] or ping me on twitter @russolsen.

Russ

More Repositories

1

eloquent_ruby_code

Source code from the book Eloquent Ruby
Ruby
109
star
2

transit

Transit marshaling to and from Go programs.
Go
51
star
3

dejour

Easy to use clojure download
C
46
star
4

cloforth

A little Forth-like language implemented in Clojure
Clojure
21
star
5

sallyforth

Very experimental forth-like programming language written in python.
Python
17
star
6

ham_radio_question_pool

All of the current questions for the FCC amateur radio license exams in machine readable format.
Ruby
11
star
7

fake_smtp

A minimal, do-nothing SMTP server
Ruby
9
star
8

expletive

Ruby
8
star
9

notroff

A plain text to OpenOffice Write filter
Ruby
6
star
10

Transit.jl

Transit format support for the Julia programming language.
Julia
5
star
11

dpir_2014

Code and slides from my 2014 talk on Design Patterns in Ruby.
Ruby
4
star
12

arachne-hello-app

Simple arachne demo application that uses the arachne-framework/hello-module.
Clojure
3
star
13

dpir_tuesday

Code from my July 2012 talk to the Ottawa Ruby Tuesday meet up
Ruby
3
star
14

cr_fake_smtp

A dummy SMTP server in Crystal.
Crystal
2
star
15

crexpletive

This is the expletive code (https://github.com/russolsen/expletive) ported to Crystal (http://crystal-lang.org).
Crystal
2
star
16

md_inc

MdInc is a simple text inclusion filter intended for use with markdown and similar text formatting utilities.
Ruby
2
star
17

same

Very permissive equality checker for Go.
Go
1
star
18

qrn

QRN is a simple, Python based static site generator.
Python
1
star
19

arachne-app1

My first arachne app, borrowed from Luke's demo app.
Clojure
1
star
20

presentations

Material from my presentations
1
star
21

aapen

Experiments in making Clojure more accessible.
Python
1
star
22

crforth

This is the a simple forth interpreter (https://github.com/russolsen/rforth) , ported to Crystal (http://crystal-lang.org).
Crystal
1
star
23

experiment

Slides from my RubyNation 2011 talk: Eloquent Explanations
1
star
24

my-new-band-name

A running list of new band names.
1
star
25

books

Simple Rails app for learning.
Ruby
1
star
26

pompous

Pompous is an assembler for Python byte code, built as a learning exercise.
Python
1
star