100% found this document useful (3 votes)
44 views

Learn Enough Ruby To Be Dangerous Write Programs Publish Gems And Develop Sinatra Web Apps With Ruby Michael Hartl pdf download

Learn Enough Ruby to Be Dangerous by Michael Hartl is a comprehensive guide that teaches readers to write programs, publish gems, and develop web applications using Ruby. The book covers core concepts of Ruby programming, object-oriented and functional programming, and culminates in building and deploying a web application. It is designed for beginners and serves as a prerequisite for more advanced Ruby on Rails tutorials.

Uploaded by

tunzimardydy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
44 views

Learn Enough Ruby To Be Dangerous Write Programs Publish Gems And Develop Sinatra Web Apps With Ruby Michael Hartl pdf download

Learn Enough Ruby to Be Dangerous by Michael Hartl is a comprehensive guide that teaches readers to write programs, publish gems, and develop web applications using Ruby. The book covers core concepts of Ruby programming, object-oriented and functional programming, and culminates in building and deploying a web application. It is designed for beginners and serves as a prerequisite for more advanced Ruby on Rails tutorials.

Uploaded by

tunzimardydy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

Learn Enough Ruby To Be Dangerous Write Programs

Publish Gems And Develop Sinatra Web Apps With


Ruby Michael Hartl download

https://ebookbell.com/product/learn-enough-ruby-to-be-dangerous-
write-programs-publish-gems-and-develop-sinatra-web-apps-with-
ruby-michael-hartl-46132216

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Learn Enough Ruby To Be Dangerous Write Programs Publish Gems And


Develop Sinatra Web Apps With Ruby Michael Hartl

https://ebookbell.com/product/learn-enough-ruby-to-be-dangerous-write-
programs-publish-gems-and-develop-sinatra-web-apps-with-ruby-michael-
hartl-46145114

Learn Enough Html Css And Layout To Be Dangerous Lee Donahoe

https://ebookbell.com/product/learn-enough-html-css-and-layout-to-be-
dangerous-lee-donahoe-43239934

Learn Enough Javascript To Be Dangerous Michael Hartl

https://ebookbell.com/product/learn-enough-javascript-to-be-dangerous-
michael-hartl-43239956

Learn Enough Developer Tools To Be Dangerous Michael Hartl

https://ebookbell.com/product/learn-enough-developer-tools-to-be-
dangerous-michael-hartl-43239958
Learn Enough Developer Tools To Be Dangerous 1st Edition Michael Hartl

https://ebookbell.com/product/learn-enough-developer-tools-to-be-
dangerous-1st-edition-michael-hartl-60673238

Learn Enough Javascript To Be Dangerous A Tutorial Introduction To


Programming With Javascript Michael Hartl

https://ebookbell.com/product/learn-enough-javascript-to-be-dangerous-
a-tutorial-introduction-to-programming-with-javascript-michael-
hartl-45491534

Learn Enough Developer Tools To Be Dangerous Git Version Control


Command Line And Text Editors Essentials Rough Cuts Michael Hartl

https://ebookbell.com/product/learn-enough-developer-tools-to-be-
dangerous-git-version-control-command-line-and-text-editors-
essentials-rough-cuts-michael-hartl-38659586

Learn Enough Html Css And Layout To Be Dangerous An Introduction To


Modern Website Creation And Templating Systems Lee Donahoe

https://ebookbell.com/product/learn-enough-html-css-and-layout-to-be-
dangerous-an-introduction-to-modern-website-creation-and-templating-
systems-lee-donahoe-43771502

Learn Enough Command Line To Be Dangerous Michael Hartl

https://ebookbell.com/product/learn-enough-command-line-to-be-
dangerous-michael-hartl-11712992
About This eBook
ePUB is an open, industry-standard format for eBooks. However,
support of ePUB and its many features varies across reading devices and
applications. Use your device or app settings to customize the presentation
to your liking. Settings that you can customize often include font, font size,
single or double column, landscape or portrait mode, and figures that you
can click or tap to enlarge. For additional information about the settings and
features on your reading device or app, visit the device manufacturer’s Web
site.
Many titles include programming code or configuration examples. To
optimize the presentation of these elements, view the eBook in single-
column, landscape mode and adjust the font size to the smallest setting. In
addition to presenting code and configurations in the reflowable text
format, we have included images of the code that mimic the presentation
found in the print book; therefore, where the reflowable format may
compromise the presentation of the code listing, you will see a “Click here
to view code image” link. Click the link to view the print-fidelity code
image. To return to the previous page viewed, click the Back button on
your device or app.
Praise for Learn Enough Tutorials

“Just started the #100DaysOfCode journey. Today marks day 1. I have


completed @mhartl’s great Ruby tutorial at @LearnEnough and am looking
forward to starting on Ruby on Rails from tomorrow. Onwards and
upwards.”
—Optimize Prime (@_optimize), Twitter post

“Ruby and Sinatra and Heroku, oh my! Almost done with this live web
application. It may be a simple palindrome app, but it’s also simply
exciting! #100DaysOfCode #ruby @LearnEnough #ABC
#AlwaysBeCoding #sinatra #heroku”
—Tonia Del Priore (@toninjaa), Twitter post
Software Engineer for a FinTech Startup for 3+ years

“I must say, this Learn Enough series is a masterpiece of education. Thank


you for this incredible work!”
—Michael King

“I want to thank you for the amazing job you have done with the tutorials.
They are likely the best tutorials I have ever read.”
—Pedro Iatzky
Learn Enough Ruby to Be
Dangerous

Write Programs, Publish Gems, and Develop


Sinatra Web Apps with Ruby

Michael Hartl

Boston • Columbus • New York • San Francisco • Amsterdam • Cape


Town
Dubai • London • Madrid • Milan • Munich • Paris • Montreal •
Toronto • Delhi • Mexico City
São Paulo • Sydney • Hong Kong • Seoul • Singapore • Taipei • Tokyo
Cover image: Philipp Tur/Shutterstock
Figures 1.4, 5.3, 10.1, 10.2, 10.15: Sinatra
Figures 1.5, 9.2: Amazon.com, Inc.
Figures 1.6, 4.3, 5.2, 5.6, 8.2, 8.5: Apple Inc.
Figures 1.7, 1.8, 8.3: GitHub, Inc.
Figures 1.9, 1.10, 10.3, 10.22: Salesforce, Inc.
Figure 2.9: Ruby-doc.org
Figures 2.11, 3.1, 3.2, 6.4: Courtesy of Mike Vanier
Figures 4.4, 4.5, 4.10, 7.12, 8.7: Michael Lovitt
Figures 5.5, 9.4: Google
Figure 7.10: Courtesy of David Heinemeier Hansson
Figures 9.3, 9.6: Wikimedia Foundation, Inc

Many of the designations used by manufacturers and sellers to distinguish


their products are claimed as trademarks. Where those designations appear
in this book, and the publisher was aware of a trademark claim, the
designations have been printed with initial capital letters or in all capitals.

The author and publisher have taken care in the preparation of this book,
but make no expressed or implied warranty of any kind and assume no
responsibility for errors or omissions. No liability is assumed for incidental
or consequential damages in connection with or arising out of the use of the
information or programs contained herein.

For information about buying this title in bulk quantities, or for special sales
opportunities (which may include electronic versions; custom cover
designs; and content particular to your business, training goals, marketing
focus, or branding interests), please contact our corporate sales department
at [email protected] or (800) 382-3419.

For government sales inquiries, please contact


[email protected].
For questions about sales outside the U.S., please contact
[email protected].

Visit us on the Web: informit.com/aw

Copyright © 2022 Softcover Inc.

All rights reserved. This publication is protected by copyright, and


permission must be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or
by any means, electronic, mechanical, photocopying, recording, or likewise.
For information regarding permissions, request forms and the appropriate
contacts within the Pearson Education Global Rights & Permissions
Department, please visit www.pearson.com/permissions.

eBook ISBN-13: 978-0-13-784418-0


eBook ISBN-10: 0-13-784418-2

ePub ISBN-13: 978-0-13-784411-1


ePub ISBN-10: 0-13-784411-5

Release 1, June 2022


Contents
Preface
About the Author

1 Hello, World!
1.1 Introduction to Ruby
1.2 Ruby in a REPL
1.2.1 Exercises
1.3 Ruby in a File
1.3.1 Exercises
1.4 Ruby in a Shell Script
1.4.1 Exercises
1.5 Ruby in a Web Browser
1.5.1 Deployment
1.5.2 Exercises

2 Strings
2.1 String Basics
2.1.1 Exercises
2.2 Concatenation and Interpolation
2.2.1 Single-Quoted Strings
2.2.2 Exercises
2.3 Printing
2.3.1 Exercises
2.4 Attributes, Booleans, and Control Flow
2.4.1 Combining and Inverting Booleans
2.4.2 Bang Bang
2.4.3 Exercises
2.5 Methods
2.5.1 Exercises
2.6 String Iteration
2.6.1 Exercises

3 Arrays
3.1 Splitting
3.1.1 Exercises
3.2 Array Access
3.2.1 Exercises
3.3 Array Slicing
3.3.1 Exercises
3.4 More Array Methods
3.4.1 Sorting and Reversing
3.4.2 Pushing and Popping
3.4.3 Undoing a Split
3.4.4 Exercises
3.5 Array Iteration
3.5.1 Exercises

4 Other Native Objects


4.1 Math
4.1.1 More Advanced Operations
4.1.2 Math to String
4.1.3 Exercises
4.2 Time
4.2.1 Exercises
4.3 Regular Expressions
4.3.1 Splitting on Regexes
4.3.2 Exercises
4.4 Hashes
4.4.1 Symbols
4.4.2 Nested Hashes
4.4.3 Exercises
4.5 Application: Unique Words
4.5.1 Exercises

5 Functions and Blocks


5.1 Function Definitions
5.1.1 Exercises
5.2 Functions in a File
5.2.1 Exercises
5.3 Method Chaining
5.3.1 Exercises
5.4 Blocks
5.4.1 Yield
5.4.2 Exercises

6 Functional Programming
6.1 Map
6.1.1 Exercises
6.2 Select
6.2.1 Exercises
6.3 Reduce
6.3.1 Reduce, Example 1
6.3.2 Reduce, Example 2
6.3.3 Functional Programming and TDD
6.3.4 Terminology Review
6.3.5 Exercises

7 Objects and Classes


7.1 Defining Classes
7.1.1 Exercises
7.2 Inheritance
7.2.1 Exercises
7.3 Derived Classes
7.3.1 Exercises
7.4 Modifying Native Objects
7.4.1 Exercises
7.5 Modules
7.5.1 Exercises

8 Testing and Test-Driven Development


8.1 Testing and Ruby Gem Setup
8.1.1 Exercises
8.2 Initial Test Coverage
8.2.1 Pending Tests
8.2.2 Exercises
8.3 Red
8.3.1 Exercises
8.4 Green
8.4.1 Exercises
8.5 Refactor
8.5.1 Publishing the Ruby Gem
8.5.2 Exercises

9 Shell Scripts
9.1 Reading from Files
9.1.1 Exercises
9.2 Reading from URLs
9.2.1 Exercises
9.3 DOM Manipulation at the Command Line
9.3.1 Exercises
10 A Live Web Application
10.1 Setup
10.1.1 Exercises
10.2 Site Pages
10.2.1 Exercises
10.3 Layouts
10.3.1 Exercises
10.4 Embedded Ruby
10.4.1 Exercises
10.5 Palindrome Detector
10.5.1 Form Tests
10.5.2 Exercises
10.6 Conclusion
Preface
Learn Enough Ruby to Be Dangerous teaches you to write practical and
modern programs using the elegant and powerful Ruby programming
language. You’ll learn how to use Ruby for both general-purpose
programming and for beginning web-application development. Although
mastering Ruby can be a long journey, you don’t have to learn everything to
get started… you just have to learn enough to be dangerous.
You’ll begin by exploring the core concepts of Ruby programming using
a combination of interactive Ruby and text files run at the command line.
The result is a solid understanding of both object-oriented programming
and functional programming in Ruby. You’ll then build on this foundation
to develop and publish a simple self-contained Ruby package, or Ruby
gem. You’ll then use this gem in a simple dynamic web application built
using the Sinatra web framework, which you’ll also deploy to the live Web.
As a result, Learn Enough Ruby to Be Dangerous is especially appropriate
as a prerequisite to the Ruby on Rails Tutorial, a bestselling web-
development tutorial by the same author.
In addition to teaching you specific skills, Learn Enough Ruby to Be
Dangerous also helps you develop technical sophistication—the seemingly
magical ability to solve practically any technical problem. Technical
sophistication includes concrete skills like version control and coding, as
well as fuzzier skills like Googling the error message and knowing when to
just reboot the darn thing. Throughout Learn Enough Ruby to Be
Dangerous, we’ll have abundant opportunities to develop technical
sophistication in the context of real-world examples.

Chapter by Chapter
In order to learn enough Ruby to be dangerous, we’ll begin at the beginning
with a series of simple “hello, world” programs using several different
techniques (Chapter 1), including an introduction to irb, an interactive
command-line program for evaluating Ruby code. In line with the Learn
Enough philosophy of always doing things “for real”, even as early as
Chapter 1 we’ll deploy a (very simple) dynamic Ruby application to the
live Web.
After mastering “hello, world”, we’ll take a tour of some Ruby objects,
including strings (Chapter 2), arrays (Chapter 3), and other native objects
like dates, hashes, and regular expressions (Chapter 4). Taken together,
these chapters constitute a gentle introduction to object-oriented
programming with Ruby.
In Chapter 5, we’ll learn the basics of functions, an essential subject for
virtually every programming language. We’ll then apply this knowledge to
an elegant and powerful style of coding known as functional programming
(Chapter 6).
Having covered the basics of built-in Ruby objects, in Chapter 7 we’ll
learn how to make objects of our own. In particular, we’ll define an object
for a phrase, and then develop a method for determining whether or not the
phrase is a palindrome (the same read forward and backward).
Our initial palindrome implementation will be rather rudimentary, but
we’ll extend it in Chapter 8 using a powerful technique called test-driven
development (TDD). In the process, we’ll learn more about testing
generally, as well as how to create a Ruby gem.
In Chapter 9, we’ll learn how to write nontrivial shell scripts, one of
Ruby’s biggest strengths. Examples include reading from both files and
URLs, with a final example showing how to manipulate a downloaded file
as if it were an HTML web page.
In Chapter 10, we’ll develop our first full Ruby web application: a site
for detecting palindromes. This will give us a chance to learn about routes,
layouts, embedded Ruby, and form handling, together with a second
application of TDD. As a capstone to our work, we’ll deploy our
palindrome detector to the live Web.

Additional Features
In addition to the main tutorial material, Learn Enough Ruby to Be
Dangerous includes a large number of exercises to help you test your
understanding and to extend the material in the main text. The exercises
include frequent hints and often include the expected answers, with
community solutions available by separate subscription at
www.learnenough.com.

Final Thoughts
Learn Enough Ruby to Be Dangerous gives you a practical introduction to
the fundamentals of Ruby, both as a general-purpose programming
language and as a web-development specialist. After learning the
techniques covered in this tutorial, and especially after developing your
technical sophistication, you’ll know everything you need to write shell
scripts, publish Ruby gems, and deploy dynamic web applications with
Ruby. You’ll also be ready for a huge variety of other resources, including
books, blog posts, and online documentation. A particularly good next step
is learning how to make dynamic database-backed web applications with
the Ruby on Rails Tutorial.

Learn Enough Scholarships


Learn Enough is committed to making a technical education available to as
wide a variety of people as possible. As part of this commitment, in 2016
we created the Learn Enough Scholarship program.1 Scholarship recipients
get free or deeply discounted access to the Learn Enough All Access
subscription, which includes all of the Learn Enough online book content,
embedded videos, exercises, and community exercise answers.
1https://www.learnenough.com/scholarship

As noted in a 2019 RailsConf Lightning Talk,2 the Learn Enough


Scholarship application process is incredibly simple: just fill out a
confidential text area telling us a little about your situation. The scholarship
criteria are generous and flexible—we understand that there are an
enormous number of reasons for wanting a scholarship, from being a
student, to being between jobs, to living in a country with an unfavorable
exchange rate against the U.S. dollar. Chances are that, if you feel like
you’ve got a good reason, we’ll think so, too.
2https://youtu.be/AI5wmnzzBqc?t=1076
So far, Learn Enough has awarded more than 2,500 scholarships to
aspiring developers around the country and around the world. To apply,
visit the Learn Enough Scholarship page at
www.learnenough.com/scholarship. Maybe the next scholarship recipient
could be you!
About the Author
Michael Hartl is the creator of the Ruby on Rails Tutorial, one of the
leading introductions to web development, and is cofounder and principal
author at Learn Enough. Previously, he was a physics instructor at the
California Institute of Technology (Caltech), where he received a Lifetime
Achievement Award for Excellence in Teaching. He is a graduate of
Harvard College, has a Ph.D. in Physics from Caltech, and is an alumnus of
the Y Combinator entrepreneur program.
Chapter 1
Hello, World!

“Ruby is a dynamic, open source programming language with a focus on


simplicity and productivity. It has an elegant syntax that is natural to read
and easy to write.” Or so says the official Ruby website. In my experience,
this description rings true—as does the declaration by Ruby’s creator that
the language is “optimized for programmer happiness.” Ruby feels natural
to read and write, has a wealth of built-in libraries, and has a powerful
object-oriented design.
Learn Enough Ruby to Be Dangerous is designed to get you started
writing practical and modern Ruby programs as fast as possible, with a
focus on the real tools used every day by software developers.
As a general-purpose programming language, Ruby is limited only by
the developer’s imagination. Ruby has enjoyed especially robust adoption
in web development, the art of writing dynamic web applications for the
World Wide Web (indeed, your trusty author is perhaps best known in the
tech world as the author of the Ruby on Rails Tutorial, an introduction to
web development using Ruby on Rails). But Ruby thrives in many other
niches as well, such as shell scripting, text parsing, and package
management.
The present tutorial can serve as either a prerequisite to the Ruby on
Rails Tutorial (especially for those who haven’t programmed much before)
or as a natural follow-on (for those who want to solidify their command of
the underlying Ruby language). In particular, Learn Enough Ruby to Be
Dangerous includes an introduction to web development with Sinatra, a
small and relatively simple Ruby web framework that is excellent
preparation for Ruby on Rails while also being a useful tool in its own
right.
As noted above, there’s more to Ruby than web development, though,
and we’ll be treating Ruby as a general-purpose programming language
right from the start. The result is a practical narrative introduction to Ruby
—a perfect complement both to in-browser coding tutorials and to the
voluminous but hard-to-navigate Ruby reference material on the Web.
Learn Enough Ruby to Be Dangerous broadly follows the structure of
Learn Enough JavaScript to Be Dangerous, which can be studied either
before or after this tutorial. Because many of the examples are the same, the
tutorials reinforce each other nicely—there are few things more instructive
in computer programming than seeing the same basic problems solved in
two different languages.
You won’t learn everything there is to know about Ruby in this tutorial
— that would take thousands of pages and centuries of effort—but you will
learn enough Ruby to be dangerous (Figure 1.1).1
1Image courtesy of Kirk Fisher/Shutterstock.
Figure 1.1: Ruby knowledge, like Rome, wasn’t built in a day.

There are no programming prerequisites for Learn Enough Ruby to Be


Dangerous, although it certainly won’t hurt if you’ve programmed before
(and suggested shortcuts for experienced devs appear in Box 1.2 below).
What is important is that you’ve started developing your technical
sophistication (Box 1.1), either on your own or using the preceding Learn
Enough tutorials. These tutorials include the following, which together
make a good list of prerequisites for this book:
1. Learn Enough Command Line to Be Dangerous
2. Learn Enough Text Editor to Be Dangerous
3. Learn Enough Git to Be Dangerous
4. Learn Enough HTML to Be Dangerous
5. Learn Enough CSS & Layout to Be Dangerous (optional)
6. Learn Enough JavaScript to Be Dangerous (optional)
All of these tutorials are available for individual purchase, and we offer a
subscription service—the Learn Enough All Access subscription—with
access to all the corresponding online courses.

Box 1.1. Technical Sophistication

An essential aspect of using computers is the ability to figure things


out and troubleshoot on your own, a skill we at Learn Enough call
technical sophistication.
Developing technical sophistication means not only following
systematic tutorials like Learn Enough Ruby to Be Dangerous, but also
knowing when it’s time to break free of a structured presentation and
just start Googling around for a solution.
Learn Enough Ruby to Be Dangerous will give us ample
opportunity to practice this essential technical skill.
In particular, as alluded to above, there is a wealth of Ruby
reference material on the Web, but it can be hard to use unless you
already basically know what you’re doing. One goal of this tutorial is
to be the key that unlocks the documentation. This will include lots of
pointers to the official Ruby site.
Especially as the exposition gets more advanced, I’ll also
sometimes include the web searches you could use to figure out how to
accomplish the particular task at hand. For example, how do you use
Ruby to manipulate a Document Object Model (DOM)? Like this: ruby
dom manipulation.
In order to learn enough Ruby to be dangerous, we’ll begin at the
beginning with a series of simple “hello, world” programs using several
different techniques (Chapter 1), including an introduction to irb, an
interactive command-line program for evaluating Ruby code. In line with
the Learn Enough philosophy of always doing things “for real”, even as
early as Chapter 1 we’ll deploy a (very simple) dynamic Ruby application
to the live Web.
After mastering “hello, world”, we’ll take a tour of some Ruby objects,
including strings (Chapter 2), arrays (Chapter 3), and other native objects
(Chapter 4). Taken together, these chapters constitute a gentle introduction
to object-oriented programming with Ruby.
In Chapter 5, we’ll learn the basics of functions, an essential subject for
virtually every programming language. We’ll then apply this knowledge to
an elegant and powerful style of coding called functional programming
(Chapter 6).
Having covered the basics of built-in Ruby objects, in Chapter 7 we’ll
learn how to make objects of our own. In particular, we’ll define an object
for a phrase, and then develop a method for determining whether or not the
phrase is a palindrome (the same read forward and backward).
Our initial palindrome implementation will be rather rudimentary, but
we’ll extend it in Chapter 8 using a powerful technique called test-driven
development (TDD). In the process, we’ll learn more about testing
generally, as well as how to create a self-contained Ruby library called a
Ruby gem (and thereby join the large and growing ecosystem of software
packages managed by Ruby’s gem-hosting service, RubyGems.org).
In Chapter 9, we’ll learn how to write nontrivial shell scripts, one of
Ruby’s biggest strengths. Examples include reading from both files and
URLs, with a final example showing how to manipulate a downloaded file
as if it were an HTML web page.
In Chapter 10, we’ll develop our first full Ruby web application: a site
for detecting palindromes. This will give us a chance to learn about routes,
layouts, embedded Ruby, and form handling. As a capstone to our work,
we’ll deploy our palindrome detector to the live Web.
In most cases, typing in code examples by hand is the most effective
way to learn, but sometimes copying and pasting is more practical. To make
the latter more convenient, all code listings from this book are available
online at the following URL:

Click here to view code image


https://github.com/learnenough/learn_enough_ruby_code_listings

Finally, experienced developers can largely skip the first four chapters,
as described in Box 1.2.

Box 1.2. For Experienced Devs

By keeping a few diffs in mind, experienced developers can skip


Chapters 1–4 of this tutorial and start with functions in Chapter 5. They
can then move quickly onto functional programming in Chapter 6,
consulting earlier chapters as necessary to fill in any gaps.
Here are some of the notable differences between Ruby and most
other languages:

Use #!/usr/bin/env ruby for the shebang line in shell scripts


(Section 1.4).
Use #{...} for string interpolation (Section 2.2).
Single-quoted strings are raw strings (Section 2.2.1).
Use puts for printing (Section 2.3).
Use elsif for else if (Section 2.4).
In a boolean context, all objects are true except nil and false
itself— even "", [], and 0 (Section 2.4.2).
Boolean methods end in a question mark, as in "".empty? (Section
2.5).
Iterate using each (Section 3.5).
Math operations are attached to a Math object; e.g., Math.sqrt(2)
(Section 4.1.1).
Hash keys are often symbols, a data type for labels (Section 4.4.1).

1.1 Introduction to Ruby


Created by Yukihiro “Matz” Matsumoto (Figure 1.2),2 Ruby was originally
designed as an object-oriented scripting language—that is, a language based
on objects that’s good for writing shell scripts. (We’ll learn more about
objects starting in Chapter 2, and we’ll cover shell scripts in Chapter 9.)
The name Ruby is a reference (in part) to the Perl programming language,
which (along with Smalltalk and Lisp) is one of Ruby’s principal design
influences.
2Image copyright © 2012 by Michael Hartl.
Figure 1.2: Yukihiro “Matz” Matsumoto, the creator of Ruby, with
author Michael Hartl at RubyConf 2012.

In order to give you the best broad-range introduction to programming


with Ruby, Learn Enough Ruby to Be Dangerous uses four main methods:
1. An interactive prompt with a Read-Evaluate-Print Loop (REPL)
2. Standalone Ruby files
3. Shell scripts (as introduced in Learn Enough Text Editor to Be
Dangerous)
4. Ruby web applications running in a web server
We’ll begin our study of Ruby with four variations on the time-honored
theme of a “hello, world” program, a tradition that dates back to the early
days of the C programming language. The main purpose of “hello, world”
is to confirm that our system is correctly configured to execute a simple
program that prints the string hello, world! (or some close variant) to the
screen. By design, the program is simple, allowing us to focus on the
challenge of getting the program to run in the first place.
Since the original application of Ruby was to write shell scripts for
execution at the command line, we’ll start by writing a series of programs
to display a greeting in a command-line terminal: first in a REPL called
interactive Ruby, or irb; then in a standalone file called hello.rb; and
finally in an executable shell script called hello. We’ll then write (and
deploy!) a simple proof-of-concept web application using the Sinatra web
framework.
(Throughout what follows, I’ll assume that you have access to a Unix-
compatible system like macOS, Linux, or the Cloud9 IDE, as described in
the free tutorial Learn Enough Dev Environment to Be Dangerous. If you
use the cloud IDE, I recommend creating a development environment
called ruby-tutorial, and be sure to choose the Ubuntu Server option as
shown in Figure 4 of Learn Enough Dev Environment to Be Dangerous.
For Mac users, although it shouldn’t matter in Learn Enough Ruby to Be
Dangerous, it is recommended that you use the Bourne-again shell (Bash)
rather than the default Z shell to complete this tutorial. To switch your shell
to Bash, run chsh -s /bin/bash at the command line, enter your password,
and restart your terminal program. Any resulting alert messages are safe to
ignore. See the Learn Enough blog post “Using Z Shell on Macs with the
Learn Enough Tutorials” for more information.)
You can check to see if Ruby is already installed by running ruby -v at
the command line to get the version number (Listing 1.1).

Listing 1.1: Checking the Ruby version.

Click here to view code image


$ ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux]

This standardizes on Ruby 3, but any version of Ruby later than 2.7 should
be fine for this tutorial. If instead you get a result like

Click here to view code image


$ ruby -v
-bash: ruby: command not found

or you get a version number earlier than 2.7, then you will have to install a
more recent version of Ruby.
The details of installing Ruby vary by system and can require applying a
little technical sophistication (Box 1.1). The different possibilities are
covered in Learn Enough Dev Environment to Be Dangerous, which you
should take a look at now if you don’t already have Ruby on your system.
In particular, if you end up using the cloud IDE recommended by Learn
Enough Dev Environment to Be Dangerous, you can update the Ruby
version as follows:

Click here to view code image


$ # on cloud IDE
$ rvm get stable
$ rvm install 3.1.1
$ rvm --default use 3.1.1

(This uses Ruby Version Manager, which comes preinstalled on the


cloud IDE.) Once that command is finished, you can verify the Ruby
version as follows:

Click here to view code image


$ ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux]

(Exact version numbers may differ.)

1.2 Ruby in a REPL


Our first example of a “hello, world” program involves a Read-Eval-Print
Loop, or REPL (pronounced “repple”). A REPL is a program that reads
input, eval-uates it, prints out the result (if any), and then loops back to the
read step. Most modern programming languages provide a REPL, and Ruby
is no exception. In Ruby’s case, it’s called irb, short for “interactive Ruby”,
and we can run it at the command line as shown in Listing 1.2.

Listing 1.2: Bringing up the irb prompt at the command line.

$ irb
>>

Here >> represents a generic irb prompt, which you can achieve on your
system by editing a special configuration file called .irbrc. Start by
creating .irbrc in your home directory using the text editor of your choice:3
3I generally use Sublime Text or Atom for everyday editing, but for editing short configuration
files and the like I usually use Vim. The reason is that Vim is incredibly fast to open and quit, which
is especially convenient when the editing task itself takes only a few seconds.

$ vim ~/.irbrc

Then fill the file with the contents of Listing 1.3. This arranges to simplify
the irb prompt as in Listing 1.2 while suppressing some annoying auto-
indent behavior.

Listing 1.3: Adding some irb configuration.


~/.irbrc

Click here to view code image


IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:AUTO_INDENT_MODE] = false

To apply this configuration, you should exit irb using exit or Ctrl-D and
then rerun the irb command.
With that bit of configuration done, we’re now ready to write our first
Ruby program using the puts command (pronounced “put-ess”), which
stands for “put string”, as seen in Listing 1.4. (We’ll start learning about
strings in Chapter 2.)

Listing 1.4: A “hello, world” program in the REPL.

Click here to view code image


>> puts "hello, world!"
hello, world!
=> nil

That’s it! That’s how easy it is to print “hello, world!” interactively with
Ruby.
If you’re familiar with other programming languages (such as
JavaScript), Listing 1.4 is notable for its lack of both parentheses and a
terminating semicolon. Cleaning up punctuation in this way is very
“Rubyish”, i.e., characteristic of Ruby.
You might also note that the final line in Listing 1.4 includes a return
value, which for puts is nil, a special Ruby value that means “nothing at
all”. We’ll learn more about nil starting in Section 2.3.

1.2.1 Exercises
1. What happens if you use print in place of puts? How would you
change print’s argument to get the result to match Listing 1.4? Hint:
Recall that \n is the typical way to represent a newline character.

1.3 Ruby in a File


As convenient as it is to be able to explore Ruby interactively, most Real
Programming® takes place in text files created with a text editor. In this
section, we’ll show how to create and execute a Ruby file with the same
“hello, world” program we discussed in Section 1.2. The result will be a
simplified prototype of the reusable Ruby files we’ll start learning about in
Section 5.2.
We’ll start by creating a directory for this tutorial and a Ruby file (with a
.rb file extension) for our hello program (be sure to exit irb first if you’re
still in the REPL):

Click here to view code image


$ cd # Change to the home directory; use cd ~/environment on
the cloud IDE.
$ mkdir -p repos/ruby_tutorial
$ cd repos/ruby_tutorial
$ touch hello.rb
Here the -p option to mkdir arranges to create intermediate directories if
necessary. Note: Throughout this tutorial, if you’re using the cloud IDE
recommended in Learn Enough Dev Environment to Be Dangerous, you
should replace the home directory ~ with the directory ~/environment.
Next, using our favorite text editor, we’ll fill the file with the contents
shown in Listing 1.5. Note that the code is exactly the same as in Listing
1.4, with the difference that in a Ruby file there’s no command prompt >>.

Listing 1.5: A “hello, world” program in a Ruby file.


hello.rb

puts "hello, world!"

At this point, we’re ready to execute our program using the ruby
command we used in Listing 1.1 to check the Ruby version number. The
only difference is that this time we omit the -v flag and instead include an
argument with the name of our file:

$ ruby hello.rb
hello, world!

As in Listing 1.4, the result is to print “hello, world!” to the terminal screen,
only now it’s the raw shell instead of an irb REPL.
Although this example is simple, it’s a huge step forward, as we’re now
in the position to write Ruby programs much longer than could comfortably
fit in an irb session.

1.3.1 Exercises
1. What happens if you give puts two arguments, as in Listing 1.6?
Listing 1.6: Using two arguments.
hello.rb

Click here to view code image


puts "hello, world!", "how's it going?"

1.4 Ruby in a Shell Script


Although the code in Section 1.3 is perfectly functional, when writing a
program to be executed in the command line shell it’s often better to use an
executable script of the sort discussed in Learn Enough Text Editor to Be
Dangerous. Indeed, as noted in Section 1.1, shell scripting was Ruby’s
original programming niche.
Let’s see how to make an executable script using Ruby. We’ll start by
creating a file called hello:

$ touch hello

Note that we didn’t include the .rb extension—this is because the filename
itself is the user interface, and there’s no reason to expose the
implementation language to the user. Indeed, there’s a reason not to: By
using the name hello, we give ourselves the option to rewrite our script in a
different language down the line, without changing the command our
program’s users have to type. (Not that it matters in this simple case, but the
principle should be clear. We’ll see a more realistic example in Section 9.3.)
There are two steps to writing a working script. The first is to use the
same command we’ve seen before (Listing 1.5), preceded by a “shebang”
line telling our system to use ruby to execute the script.
Ordinarily, the exact shebang line is system-dependent (as seen with
Bash in Learn Enough Text Editor to Be Dangerous and with JavaScript in
Learn Enough JavaScript to Be Dangerous), but with Ruby we can ask the
shell itself to supply the proper command. The trick is to use the ruby
executable available as part of the shell’s environment (env):

#!/usr/bin/env ruby

Using this for the shebang line gives the shell script shown in Listing 1.7.

Listing 1.7: A “hello, world” shell script.


hello

Click here to view code image


#!/usr/bin/env ruby

puts "hello, world!"

We could execute this file directly using the ruby command as in


Section 1.3, but a true shell script should be executable without the use of
an auxiliary program. (That’s what the shebang line is for.) Instead, we’ll
follow the second of the two steps mentioned above and make the file itself
executable using the chmod (“change mode”) command combined with +x
(“plus executable”):

$ chmod +x hello

At this point, the file should be executable, and we can execute it by


preceding the command with ./, which tells our system to look in the
current directory (dot = .) for the executable file. (Putting the hello script
on the PATH, so that it can be called from any directory, is left as an
exercise.) The result looks like this:

$ ./hello
hello, world!
Success! We’ve now written a working Ruby shell script suitable for
extension and elaboration. As mentioned briefly above, we’ll see an
example of a real-life utility script in Section 9.3.
Throughout the rest of this tutorial, we’ll mainly use irb for initial
investigations, but the eventual goal will almost always be to create a file
(either pure code or HTML) containing Ruby.

1.4.1 Exercises
1. By moving the file or changing your system’s configuration, add the
hello script to your environment’s PATH. (You may find the steps in
Learn Enough Text Editor to Be Dangerous helpful.) Confirm that
you can run hello without prepending ./ to the command name.
Note: If you have a conflicting hello program from following Learn
Enough JavaScript to Be Dangerous, I suggest replacing it—thus
demonstrating the principle that the file’s name is the user interface,
and the implementation can change language without affecting users.

1.5 Ruby in a Web Browser


Although originally designed for shell scripting, Ruby’s flexibility and
expressiveness led Danish programmer David Heinemeier Hansson (often
known as “DHH” for short) to choose it to implement a project-
management application called Basecamp. From Basecamp, DHH extracted
a general-purpose framework for making dynamic web applications, which
he named Ruby on Rails (a satirical reference to a heavyweight Java
framework called “Struts”). Due in large part to the success of the Rails
framework, Ruby has since become a major player in web development. In
recognition of this, our final example of a “hello, world” program will be a
live web application, written in the simple but powerful Sinatra micro-
framework (Figure 1.3).4
4Image courtesy of UtCon Collection/Alamy Stock Photo.
Figure 1.3: Frank Sinatra, notable both for his mellifluous singing
voice and his astonishing skill at web development.
We’ll begin by installing a self-contained piece of Ruby software,
known as a Ruby gem, called sinatra. First, we’ll do a little preparation by
adding some configuration settings to prevent the time-consuming
installation of local Ruby documentation, which needs to be done only once
per system (definitely don’t worry about trying to understand this
command):

Click here to view code image


$ echo "gem: --no-document" >> ~/.gemrc

Now we’re ready to install sinatra using the gem command, which is
installed automatically as part of Ruby:

$ gem install sinatra -v 2.2.0

Believe it or not, this one command installs all of the software needed to
run a simple but full-strength web application on our local system (where
“local” might refer to the cloud if you’re using the cloud IDE recommended
in Learn Enough Dev Environment to Be Dangerous).
Although the code for the “hello, world” web app uses commands that
we haven’t covered yet, it’s a straightforward adaptation of the example
program on the Sinatra homepage (Figure 1.4). Being able to adapt code
you don’t necessarily understand is a classic hallmark of technical
sophistication (Box 1.1).
Figure 1.4: A sample program from the Sinatra homepage.

We’ll put our “hello, world” app in a file called hello_app.rb:

$ touch hello_app.rb

The code itself closely parallels the program in Figure 1.4, as seen in
Listing 1.8. (If you’re wondering about the use of both single-quoted strings
in Listing 1.8 and the double-quoted strings we saw in Section 1.2, you’re
ahead of the game; we’ll learn the difference between the two in Chapter 2.)

Listing 1.8: A “hello, world” web app.


ruby_tutorial/hello_app.rb

Click here to view code image


require 'sinatra'

get '/' do
'hello, world!'
end

We’ll cover the techniques in Listing 1.8 in more detail starting in Section
5.4, but the basic idea is that it defines the behavior for the root URL / when
responding to an ordinary browser request (known as GET). The response
itself is the required “hello, world!” string, which will be returned to the
browser as a (very simple) web page.
To run the web application in Listing 1.8, all we need to do is call the
hello_app.rb file using the same ruby command we used in Section 1.3;
the sinatra gem magically takes care of the rest (Listing 1.9).

Listing 1.9: Running the Sinatra app with ruby.

Click here to view code image


$ ruby hello_app.rb
== Sinatra has taken the stage on 4567 for development with
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop

Here I’ve shown the output on my system, which runs a local web server on
port number 4567 by default. This means you can view the app by visiting
localhost:4567 in your browser. As seen in Figure 1.5, the effect on the
cloud IDE is slightly different, but the idea is basically the same, and in
either case the result should look something like Figure 1.6.
Figure 1.5: The “local” server running on the cloud IDE.
Figure 1.6: The hello app running locally.

It’s worth noting that using Ruby to run a Sinatra app as in Listing 1.9
suffers from a major inconvenience: Seeing the effect of changes to the
code requires quitting and restarting the server. This is fine for a quick
change, but quickly becomes impractical for larger projects. We’ll see how
to get around this restriction using the rerun gem starting in Section 10.1.

1.5.1 Deployment
Now that we’ve got our app running locally, we’re ready to deploy it to a
production environment. This used to be practically impossible to do in a
beginning tutorial, but nowadays we can do it using a great hosting platform
called Heroku. There’s a bit of overhead to deploy something the first time,
but deploying early and often is a core part of the Learn Enough philosophy
of shipping (Box 1.3). Moreover, a simple app like “hello, world” is the
best kind of app for first-time deployment, because there’s so much less that
can go wrong.

Box 1.3. Real Artists Ship

As legendary Apple cofounder Steve Jobs once said: Real artists


ship. What he meant was that, as tempting as it is to privately polish in
perpetuity, makers must ship their work—that is, actually finish it and
get it out into the world. This can be scary, because shipping means
exposing your work not only to fans but also to critics. “What if people
don’t like what I’ve made?” Real artists ship.
It’s important to understand that shipping is a separate skill from
making. Many makers get good at making things but never learn to
ship. To keep this from happening to us, we’ll follow the practice
started in Learn Enough Git to Be Dangerous and ship several things in
this tutorial. Shipping the “hello, world” app in this section is only the
beginning!

As with the GitHub Pages deployment option used in previous tutorials


(Learn Enough CSS & Layout to Be Dangerous and Learn Enough
JavaScript to Be Dangerous among them), our first step is to put our
project under version control with Git (as covered in Learn Enough Git to
Be Dangerous, which you should consult now if your system isn’t already
configured for Git):

Click here to view code image


$ git init
$ git add -A
$ git commit -m "Initialize repository"

Although not strictly necessary, it’s a good idea to push any newly
initialized repository up to a remote backup. As in previous Learn Enough
tutorials, we’ll use GitHub for this purpose (Figure 1.7).5
5Previous versions of this tutorial used GitLab instead of GitHub because at the time private
repos at GitHub weren’t free. Since videos are harder to update than text, the screencasts that
accompany this book still use GitLab, but the steps for GitHub are much the same (and are covered
in several other Learn Enough tutorials, including Learn Enough Git to Be Dangerous). As usual, use
your technical sophistication (Box 1.1) to resolve any discrepancies.
Figure 1.7: Creating a new repository at GitHub.

Because web apps sometimes include sensitive information like


passwords or API keys, I like to err on the side of caution and use a private
repository. Accordingly, be sure to select the Private option when creating
the new repository at GitHub, as shown in Figure 1.8.
Figure 1.8: Using a private repo.

Next, configure your local system with the remote repository and push it
up (taking care to fill in <username> with your GitHub username and using
a GitHub personal access token when prompted for a password):

Click here to view code image


$ git remote add origin
https://github.com/<username>/ruby_tutorial.git
$ git push -u origin main

Because videos are relatively hard to update, the screencasts that


accompany this book use master, which was the default branch name for
the first 15+ years of Git’s existence, but the text has been updated to use
main, which is the current preferred default. See the Learn Enough blog post
“Default Git Branch Name with Learn Enough and the Rails Tutorial” for
more information.
Next you’ll have to create and configure a new Heroku account if you
don’t already have one. The first step is to sign up for Heroku. As part of
this, you should set up Multi-Factor Authentication on your account.
The next step is to check to see if your system already has the Heroku
command-line client installed:

Click here to view code image


$ heroku --version # will work only if heroku is installed
heroku: command not found

This will display the current version number if the heroku command-line
interface (CLI) is available, but on most systems it will be necessary to
install the Heroku CLI by hand.6 In particular, if you’re working on the
cloud IDE, you can install Heroku using the command shown in Listing
1.10.
6toolbelt.heroku.com

Listing 1.10: The command to install Heroku on the cloud IDE.


Click here to view code image
$ source < (curl -sL
https://cdn.learnenough.com/heroku_install)

After running the command in Listing 1.10, you should now be able to
verify the installation by displaying the current version number (details may
vary):

Click here to view code image


$ heroku --version
heroku/7.59.2 linux-x64 node-v12.21.0

Once you’ve verified that the Heroku command-line interface is


installed, the next step is to use the heroku command to log in to your
account. If you’re using a native development environment, simply type
heroku at the command line, which will automatically spawn a browser and
let you log in with your Heroku email and password:

Click here to view code image


$ heroku login # on a native system but not on the cloud
IDE
$ # Spawns a browser window. Log in with your email and Heroku
password.

If you’re using the cloud IDE, you need to pass the --interactive
option, which prevents the heroku command from trying to spawn a
browser (which wouldn’t work in the cloud). You also won’t be able to log
in using your regular Heroku password; instead, you’ll have to create an
API Key using the interface on your Heroku Account page (Figure 1.9).
Once you’ve followed that step (and saved the result somewhere safe), you
can log in using your email and the Account Key as your password:
Figure 1.9: The API key at Heroku.

Click here to view code image


$ heroku login --interactive # on the cloud IDE
Email: <your email>
Password: <your API Key, NOT your Heroku password>

After you’ve logged in, you can use the heroku create command to
create a place on the Heroku servers for the sample app to live (Listing
1.11).
Finally, use the heroku create command to create a place on the Heroku
servers for the sample app to live (Listing 1.11).

Listing 1.11: Creating a new application at Heroku.

Click here to view code image


$ heroku create
Creating app... done, damp-depths-3
https://damp-depths-3.herokuapp.com/ |
https://git.heroku.com/damp-depths-3.git

The heroku command creates a new subdomain just for our application,
available for immediate viewing. There’s nothing there yet, though, so let’s
get busy deploying.
The final steps involve some configuration that you can practically copy
(with only minor modifications) from the Heroku documentation. We need
only two more files, a “Rackup” (.ru) file called config.ru and a Gemfile
specifying which gems our app uses (in this case, sinatra and puma, which
is a production-grade web server):

$ touch config.ru Gemfile

Using your favorite text editor, fill these files with the contents shown in
Listing 1.12 and Listing 1.13.

Listing 1.12: The Rack configuration file.


ruby_tutorial/config.ru

Click here to view code image


require './hello_app'
run Sinatra::Application

Listing 1.13: The hello app Gemfile.


ruby_tutorial/Gemfile

Click here to view code image


source 'https://rubygems.org'

ruby '3.1.1' # Change this line if you're using a different


Ruby version.

gem 'sinatra', '2.2.0'


gem 'puma', '5.6.4'

Now we’re almost ready to deploy. We first need to bundle our gems
(well, gem) using Bundler, and then add the files to Git:

Click here to view code image


$ gem install bundler -v 2.3.10
$ bundle _2.3.10_ install
$ bundle _2.3.10_ lock --add-platform x86_64-linux
$ git add -A
$ git commit -m "Add deployment configuration"

Note that the first three lines include an exact Bundler version number
(2.3.10) for maximum compatibility. The third line may or may not be
necessary depending on the exact system you’re using, but in any case it
does no harm to include it.
Finally, we can deploy to Heroku with a simple git push:

$ git push heroku main

That’s it! Once the deployment is complete, our hello app is running in
production (Figure 1.10). (Note: Heroku displays the Web URL of the app
upon deployment, but you can run heroku apps:info at any time to see it
again.)
Figure 1.10: The hello app running in production.

“It’s alive!” (Figure 1.11).7


7Image courtesy of Niday Picture Library/Alamy Stock Photo.
Another Random Document on
Scribd Without Any Related Topics
The table was cleared by so many hands that they were in the
way of one another; then the quintet adjourned to the windward
side of the house, under the vine-clad arbor, and began to exchange
questions. Suddenly Grace said:—
"There's something new and strange about Caleb—something
besides his change of appearance and his happiness, and I can't
discover what it is."
"Perhaps," said Mary, with a mischievous twinkle in her eyes, "'tis
his grammar."
Caleb's eyes expressed solicitude as they turned toward Grace,
and they indicated great sense of relief when Grace clapped her
hands and exclaimed:—
"That is it!"
"Well," said Caleb, "it does me good to know that the change is
big enough to see, for it's taken a powerful lot o' work. I used to be
at the head of the grammar class when I was a boy at school, but
'Evil communications corrupt good manners,' as the Bible says, an'
I've been hearin' the language twisted ev'ry which way ever since I
left school. I never noticed that anythin' was wrong till I got into
some long talks with Mary, an' even then I didn't suppose that 'twas
my manner o' speech that once in a while made her twitch as if a
skeeter had suddenly made himself too familiar. One evenin'—I
didn't know till afterwards that she'd had an extra hard day at the
store, an' had brought a nervous headache home with her—she
gave an awful twitch while I was talkin', an' then she whispered
'Them!' to herself, an' looked as disapprovin' as a minister at a
street-fight. Then all of a sudden my bad grammar came before my
eyes, as awful as conviction to a sinner. But I was tryin' to set my
best foot forward, so I went on:—
"'I said "them" for "those" just now, perhaps you noticed?'
"'I believe I did,' said she.
"'Well,' said I, 'that word was pounded into me so hard at school
one day that I've never been able to get rid of it. You see, I was the
teacher's favorite, after a fashion, because it was known that I was
expectin' to study for the ministry, so the teacher kept remindin' me
that grammar was made to practise as well as recite, an' 'twasn't of
any use to use the language correctly in the class if I was goin' to
smash it an' trample on the pieces on the playground. I took the
warnin' an' one day, when four of us boys were havin' a game of
long-taw at recess I said somethin' about "those" marbles. One of
the boys jumped as if he had been shot, and when he came down
he rolled back his lips an' said "Those!" kind o' contemptuous-like,
an' another snickered "Those!" an' the other growled "Those!" an'
then the first one said, "Fellers, Preachy's puttin' on airs; let's knock
'em out of him," an' then all of 'em jumped on me an' pounded me
until the bell rang us in from recess, an' from that time to this I've
stuck to "them" like a penitent to the precious promises.'
"Well, she had a laugh over that; she said afterward that it cured
her headache, but after quietin' down she said, lookin' out o' the
side o' her face kind o' teasin'-like, an' also mighty bewitchin':—
"'What did the boys do to make you say "ain't" for "haven't"?'
"Then I was stuck, an' laughed at myself as the best way of
turnin' it off, but for the rest of the evenin' I was chasin' the old
grammar back through about twenty years of army talk an' store
talk, an' 'twas harder than a dog nosin' a rabbit through a lot full o'
blackberry patches, an' I reckon I lost the scent a good many times.
I stayed in the city that night, so as to get into a bookstore an' a
grammar book early next mornin', an' I dived into that book ev'ry
chance I got, in the hoss-cars an' ev'rywhere else, an' when I was
on the ocean an' not sayin' my prayers, nor readin' the Bible, I was
doin' only three things, an' generally doin' all of 'em at once,—
thinkin' of Mary, keepin' my head an' shoulders up as my old soldier-
chum Jim had made me promise to do, an' puttin' Claybanks English
into decent grammatical shape. I tried to stop droppin' my 'g's' too,
for she seemed to think they deserved a fightin' chance o' life, even
if they did come in only on the tail-ends of words; I'd have got along
fairly well at it, if it hadn't been for the English people, but some of
them seem to hate a 'g' at the end of a word as bad as if it was an
'h' at the beginnin', which is sayin' a good deal. But see here, isn't it
most church time? I s'pose the sooner I take up my cross, the less
I'll dread it."
"Caleb," exclaimed Grace, in genuine surprise, "it can't be possible
that you've been backsliding, and learning to dislike religious
services?"
"Oh, no," Caleb replied, looking quizzically at his wife; "but you're
the only old acquaintances I've met since I was married, an' at
church I'll meet two or three hundred, an' Claybanks people don't
often have any one new to look at an' talk about, an' any surprise of
that kind is likely to hit most of 'em powerful hard."
"Go very early," Grace suggested, "and sit as far front as possible.
Philip and I will break the news to the minister before he reaches the
church, and we'll stand outside and tell the people as they arrive, so
that they can collect their wits and manners by the time the service
ends."
"That'll be a great help," said Caleb. Then he drew Grace aside
and whispered with a look that was pathetic in its appeal: "Try to
make her understand, won't you, that our folks are a good deal nicer
than they look? You went through it alone, a few months ago. I saw
your face, an' my heart ached for you, but to-day I'm tremblin' for
Mary. What do you s'pose she'll think after she's looked around?"
"About what I myself did," Grace replied. "I thought, 'I've my
husband,' and from that moment Philip was far dearer to me than he
had been."
"Is that so? Glory! Mary, put on your bonnet. Let's be off for
church."
XXV—LOOKING AHEAD
"WELL, Philip," said Caleb, as the two men met on the piazza
before sunrise Monday morning, "as Sunday's gone an' as there's no
one here but you an' I, let's talk business a little bit. You mustn't
think that my having taken a wife is going to make me an extra drag
on you, an' right after a cyclone, too. My salary's enough to support
two on the best that Claybanks can provide, an' if you're hard
pushed, I can get along without drawin' anythin' for a year, for I've
always kept a few hundred ahead against a time when I might break
down entirely. I've told Mary how your wife's been in the store a
great part of the time, an' there's nothin' that Mary'd like better than
to do the same thing, if agreeable to you an' Mrs. Somerton. She's
had practical trainin' at it, you know."
"She'll be worth her weight in gold to us," Philip replied, "for I
foresee a busy future, about which I've much to say to you. The
cyclone, instead of depressing the people, seems to have nerved
them to new hope, for the town has received much free advertising;
a lot of city newspapers sent men down here to describe the horrors
of the affair, and as there were no actual horrors, and the men
wanted something of which to make stories, that brother-in-law of
yours, who is about as quick-witted a young chap as I ever met,
filled their heads with the natural resources of Claybanks,—rich soil,
drained swamps, plenty of valuable commercial timber, water-power
available at short notice, whenever manufacturers might demand it,
and, of course, the great deposit of brick clay from which the town
got its name. I predict that there will be a lot of chances to make
money outside of the store, so the more help we can have in the
store, the better. By the way, I wonder what Truett has been up to
this morning. I heard hammering awhile ago, in the direction of the
warehouse. Ah! I remember—putting up the old sign over the door—
uncle's old sign; it was carried about a mile from town by the
cyclone and brought back by a man who thought, and very correctly,
that I'd like to preserve it. Let's go around a moment and see how it
looks, and remind ourselves of old times."
As they reached the front of the warehouse, Caleb lost the end of
a partly uttered sentence, for over the old sign he saw a long board
on which was painted, in large, black letters:—
SOMERTON & WRIGHT,

SUCCESSORS TO

"Who did that?" Caleb gasped.


"Truett," Philip replied. "He did it by special request, and I'm
afraid he worked a little on Sunday, but Mrs. Somerton and I thought
it a work of necessity. You see," Philip continued, in a matter-of-fact
manner, and ignoring Caleb's astonished look, "by the terms of Uncle
Jethro's will I was to provide for you for life and to your own
satisfaction, and 'tis quite as easy to do it this way as on the salary
basis. Besides, 'twill put those benevolent societies out of their
misery, and put an end to their questions, every two or three
months, as to the likelihood of the property reverting to them. You'll
have me in your power as to terms, but I know you'll do nothing
unfair. Let's have articles of co-partnership drawn up, on the basis of
equal division of profits in the entire business—store, farms, houses,
etc. I wrote you of the lump of money I got for my father's old
mining stock. That, of course, is my own; but if the firm runs short
of ready cash at any time I will lend to it at the legal rate of interest,
so nothing but a very bad crop year can cripple us. Besides, I shall
want to operate a little on the outside, so the store will need an
additional manager who shall also be an owner—not a clerk, as
you've insisted on being."
"But, Philip," said Caleb, who had collapsed on an empty box in
front of the store, "I've never had any experience as a boss."
"Nor as a married man, either," Philip replied, "yet you've
suddenly taken to the part quite naturally and creditably! The main
facts are these: I'm satisfied that the past success of the store
business has been due quite as much to you as to Uncle Jethro, and
all the people agree with me. I couldn't possibly get along without
you, nor feel honest if I continued to take more than half of the
proceeds. Why not go tell the story to your wife, as an eye-opener?
I think it might give her a good appetite for breakfast, and improve
her opinion of Claybanks and the general outlook. It might cheer her
farther to be told that her brother is the right man in the right place,
and bids fair to become the busiest man in the county."
"I'll tell her, an' I don't doubt that 'twill set her up amazingly. But,
Philip—" here Caleb looked embarrassed, "you haven't—don't you
think you could make out to say somethin' to me about her?"
"You dear old chap,—'young chap' would be the proper
expression,—where are your eyes, that you haven't seen me
admiring her ever since you brought her to us yesterday morning?
She's a beauty with a lot of soul, and she's a wonderfully clever,
charming woman besides, and I never saw a bride who seemed
deeper in love. I can't ever thank you enough for finding such capital
company for my wife. I expected to be impressed, for Grace has
raved about her ever since you first wrote of meeting her, but Grace
left much untold."
"I was afraid you might think she took up with me too easily,"
said Caleb; "but when, after we were married, I told her I never
would forgive myself if I did not make her life very happy, she said
she had no fears for the future, and that I mustn't think she took me
only on my own say-so, for she'd had a lot of letters from your wife
about me, all to the effect that I was the honestest, kindliest, most
thoughtful, most unselfish man in the world, except you. Mary had
great confidence in the judgment of your wife, whom she
remembered as a very discreet young woman and a good judge of
human nature. Her brother, too, unloaded on her a lot of
complimentary things that he'd managed to pick up out here about
me. Now, as a married man, an' a good friend of mine, what do you
honestly think of my future?"
"Nothing but what is good. You've still half of your life before you,
and if you're really rid of malaria, and if that Confederate bullet will
cease troubling you, you ought to tread on air and live on sunshine
for the remainder of your days."
"Speakin' of bullets," said Caleb, tugging at one end of a double
watch-chain, and extracting from his pocket something which
resembled a battered button, "how's that, for the wicked ceasin'
from troublin' an' the weary bein' at rest? For my first two or three
days at sea I couldn't see any good in sea-sickness, except perhaps
that it had a tendency to make a man willin' to die, an' even that
view of it didn't appeal very strongly to me, circumstances bein'
what they were. One day when I was racked almost to death, I felt
an awful stitch in my side. I was weak an' scared enough to b'lieve
almost anythin' awful, so I made up my mind that I must have
broken a rib durin' my struggles with my interior department, an'
that the free end of it was tryin' to punch its way through to
daylight. So I sent for the ship's surgeon, an' he, after fussin' over
me two or three minutes, and doin' a little job of carvin', brought us
face to face—I an' my old acquaintance from the South. I was so
glad that I could 'a' hugged the Johnny Reb that fired that bullet, an'
I never was seasick after that. But that's enough about me. Tell me
somethin' about business. Do you think the cyclone has hurt you a
lot, for the present?"
"It destroyed the store and its contents, and I don't expect to get
any insurance, but I haven't lost any customers. On the other hand,
some farmers are so sorry for me, I being the only merchant that
was entirely cleaned out, that they are going to trade with us next
year. Besides, much of our stock was old, and never would have sold
at any price, while an entirely new stock is a great attraction to all
classes of customers. We'll have a new store building up pretty soon,
if Truett is as able as he thinks himself and as I think him. Let's go
back to the wreck a moment; he generally has some men at work by
sunrise, clearing away, so as to get at the foundations and ascertain
their condition."
Apparently the young engineer was amusing himself, for they
found him hammering a brick into small bits and examining the
fractured surfaces. As Philip and Caleb joined him, he said:—
"This is a mystery. How on earth do you suppose this kind of brick
got into Claybanks?"
"Easiest way in the world," Caleb replied, "seein' 'twas made here.
'Tisn't a good color, but, gentlemen, I saw whole houses on some o'
the best streets in New York made of brick of about this color. They
were better shaped, an' fancy-laid, but—"
"Excuse me, Caleb," said Truett, excitedly, "but do you mean to
say that this brick was made here, in Claybanks, of Claybanks clay?"
"That's the English of it," Caleb replied, "an' all the bricks of all
the chimneys an' fireplaces in the town are of the same clay."
"Oh, no; they're red."
"Yes, but that's because of one of Jethro's smartnesses.
Wonderful man, Jethro Somerton was. The way of it was this: a
newcomer here that wanted to put on some style, like he'd been
used to in Pennsylvany, got your uncle to order enough red paint for
him to cover a big new barn. Just 'fore the paint got here the barn
was struck by lightnin', an' the new barn had to be of rough slabs,
an' the man was glad enough to get 'em, too. Meanwhile Jethro was
stuck with a big lot o' red paint, for nobody else felt forehanded
enough to paint a barn. Jethro cogitated a spell, an' then he said
quite frequent an' wherever he got a chance, that Claybanks was a
sad, sombre-lookin' place; needed color, specially in winter, to make
it look kind o' spruce-like. That set some few people to white-washin'
their houses, an' when them that couldn't afford to do that much
kind o' felt that some o' their neighbors were takin' the shine off of
'em, Jethro up an' said, 'Any man can afford to paint his chimney
red, anyhow, an' a red chimney'll brighten up any house.' So, little
by little at first, but afterwards all at a jump, he got rid o' that lot o'
red paint, an' had to order more, an' in the course o' time it got to
be the fashion, quite as much as wearin' hats out o' doors."
"That explains," said Truett, apparently relieved at mind, "why
I've not noticed the brick before. I've seen two or three foundation
walls, but I supposed, from their color, that they were merely mud-
stained. Now let me give you two men a great secret, on condition
that you let me in on the ground floor of the business end of it. Brick
of this quality and color, properly moulded and baked, is worth about
three times as much as ordinary red brick: I'll get the exact figures
within a few days. I know that there is money in sending it to New
York, from no matter what distance. Some of it is used even in
indoor decoration."
"Whe—e—e—ew!" whistled Philip.
"Je—ru—salem!" ejaculated Caleb. "To think that the clay has
been here all these years without anybody knowing its real value!"
"How could any one be expected to know about anything that
existed in an out-of-the-way hole-in-the-ground like Claybanks?"
"Sh—not so loud!" said Philip. "Such talk in any Western town is
worse than treason."
"'Tis reason, nevertheless. There might be a vein of gold here,
but how could the world ever learn of it? Who owns the clay banks?
Can't we get an option on them?"
"They belong to the town, which charges a royalty of twenty-five
cents per thousand bricks," said Caleb. "They've brought less than a
hundred dollars, thus far."
"Oh, this is dreadful!—splendid, I mean! A brick-making outfit
isn't expensive, and fuel with which to burn the bricks is cheap.
Can't we three organize a company, right here, in our hats or
pockets, and get the start of any and all others in the business?
'Twill cost us about two dollars per thousand, I suppose, to haul the
bricks to the railway station, but even then there will be a lot of
money in the business. If we could have a railway—pshaw, men—
Claybanks must have a railway! I've selected several routes, in off-
hand fashion, over the three miles of country between here and the
nearest railway station; there would be absolutely no bridging to do,
nor any grading worth mentioning, so the three miles could be built
for thirty thousand dollars. Let's do it!"
"Truett," said Philip, impressively, "go slow—very slow, or you'll
have inflammation of the brain. Worse still, I shall have it. Caleb may
escape, for he has the native Westerner's serene self-confidence in
his own town and section; but I'm a Claybanker by adoption merely.
First, you open a mine of wealth before our eyes, in the claybanks.
Then you tempt us to make bricks for rich New Yorkers and others.
Then you offer us a railway for thirty thousand dollars,—more
money, to be sure, than could be raised here in thirty years,—and
you do all this before breakfast on Monday morning. Come into the
house with us; I shall faint with excitement if I don't get a cup of
coffee at once."
"Make light of it, if you like," said Truett, "but will you look at the
brick-making figures,—cost of plant, manufacture, and freight, also
the selling price,—if I can get them from trustworthy sources?"
"Indeed I will—our firm will; won't we, Caleb?"
"I've been wantin' for years to see such a lot of figures," said
Caleb, placidly, "an' to see the railroad figures we could touch. I've
seen some of the other kind, once in a while."
"I hope too many cooks haven't spoiled the broth," said Mary, at
the breakfast table, from behind a large breast-knot of roses. "I
found in the garden what Grace pronounces a lot of weeds; but I've
made a salad of them, and I shall feel greatly mortified if all of you
don't enjoy it."
"We are prepared to expect almost anything delightful from what
has been accounted worthless," said Philip, "after having listened to
some of your brother's disclosures this morning. Eh, Caleb?"
"Yes, indeed," replied Caleb, with an "I-told-you-so" air. "I never
doubted that a lot of good things would be developed at Claybanks,
when the right person came along to develop 'em."
"Think of it, Mary!" said Truett. "You remember that magnificent
house of old Billion's, on Madison Avenue—a house of yellowish
brown brick? Well, the foundation of Somerton's old store is of just
such brick, and it was made here, years ago, of the clay for which
the town was named."
Mary's eyes opened wide as she replied:—
"What a marvellous country! Why, Grace, one of our firm, at the
old store, boasted of having a chimney breast of that same brick, as
if it were something quite rare and costly."
"Why don't you build the new store of it, Phil?" Grace asked.
"That's a happy thought!" said Truett. "Now, Somerton, what do
you say to my brickyard plan? Put up the first solid building in
Claybanks—set the fashion. Think of how 'twould advertise your
business and make your competitors look small by comparison."
"Very well. See how quickly it can be done, if at all, and then we
will talk business. We must have the warehouse clear by the
beginning of the pork-packing season, less than four months
distant." Then he smiled provokingly, and continued, "Perhaps,
however, it will be better to build the new store of wood, as already
planned, so you can give most of your time to building a railroad, so
that we may get our golden bricks, and other goods, to market."
"There's sense in that," said Truett, taking the remark seriously.
"As to the road, you may rest assured that my figures are within the
extreme cost."
"My dear boy," said Philip, "far be it from me to dispute an
engineer's estimates; but for some years in New York I was clerk
and correspondent for a firm of private bankers who dabbled in
railways, and I assure you that they never found any that cost but
ten thousand dollars per mile."
"Perhaps not, for most railways are built on credit—generally on
speculation, and largely for the special benefit of the builders, but
our road—"
"What are these men talking about?" Mary asked of Grace.
"A railway from Claybanks to the nearest station we now have,"
said Philip. "Women love imaginative creations, Truett, so tell them
all about it."
"There is no imagination in this," Truett retorted, "but perhaps
they will condescend to listen to facts. Most companies are obliged
to average the cost of their lines over a great stretch of territory.
They have bridges and trestles to build, cuts to make, low ground to
fill, and they must pay high prices, at portions of their line, for right
of way, and they stock and bond their companies at ruinous rates to
get the necessary money. As I've already said, none of the routes I
have selected requires a single bridge, trestle, or filling, and the right
of way, at the highest prices of farm land in this county, won't
exceed a thousand dollars per mile."
"'Twon't cost a cent a mile," said Caleb. "Any farmer in these
parts will give a railroad free right of way through his land, and say
'Thank you' for the privilege of doing it. If his house or barn is in the
way, he will move it; he'll even let the line run over his well, and dig
himself a new one, for the sake of having railroad trains for him and
his family to stare at, for the trains kind o' bring farmers in touch
with the big world of which they never see anything. If everything
else can be arranged, you may safely count on me to coax right of
way for the entire line."
"Score one for Truett!" said Philip; "proceed, Mr. Engineer."
"Thank you, and thanks to Caleb. The items of cost will be only
road-bed, ties, and metal. A single track, with heavy rails, can be
metalled out here for less than three thousand dollars per mile: that
means nine thousand dollars for the three miles, and that should be
the total cash outlay, for the road-bed and ties can be provided, by
local enterprise, without money."
"Pardon my thick head," said Philip, "but how?"
"By organizing a stock company with shares so small that any
farmer can subscribe, his subscription being payable in ties, which
he can cut from his own woodland, or in labor with pick, shovel,
horses, plough, scraper—whatever he and we can best use. Fix a
valuation on ties, and on each class of labor, and pay in stock. 'Tis
simply applying our drainage-ditch plan to a larger operation, though
not very much larger, and one that will be attractive to a far greater
number of men. Do this, and you merchants and other men of
money supply the cash to buy the metal, and I'll guarantee to have
that road completed in time to haul to market your wheat, pork,
corn, and other produce on any day of the coming winter, regardless
of the weather. Caleb tells me that you merchants have often lost
good chances of the market because the roads between here and
the station were so soft or so rough that a loaded wagon couldn't
get over them. There are tens of thousands of cords of firewood still
standing here, on land that ought to be under cultivation, but the
farmers have no incentive to cut it, for there is no market but this
little town. The railroad would get it to market, and at good cash
prices, and thus doubly benefit the farmers. I'm told that the water-
power of the creek has been holding up the Claybanks heart for
years; and I know that there are enough varieties of commercial
timber here to occupy several mills a long time, but no one is going
to haul machinery in, and his output away, over three miles of mud
or frozen clods."
"True as Gospel—every word of it," said Caleb. "I've heard Jethro,
an' Doc Taggess, an' ev'ry other level-headed man in town say the
same thing for years."
"I fully agree with them," said Philip, "but let's go back to figures
a moment. I've heard nothing yet about the cost of locomotives, and
other rolling stock—mere trifles, of course,—yet necessary."
"We should not be expected to supply them," Truett explained.
"The road which ours will feed will be glad to supply them, as all
roads do for short spurs on which anything is to be handled. It
would be idiotic to buy rolling stock for a road which at first won't
have enough business to justify one train a day. When there's
anything to do, the old company will send down a short train from
the nearest siding; the run wouldn't require fifteen minutes. You
Eastern people who are accustomed to a thickly populated country,
with many through trains daily, don't know anything about the
business methods of the sparsely settled portions of the West,
especially on spurs of a railway line."
"He's right about rolling stock," said Caleb. "Ten years ago the
railroad company, over yonder, told Jethro an' a committee that went
from here to see 'em that if we'd build the spur, they'd do the rest.
But they stood out for a solid road-bed, as good as their own, an' for
heavy steel rails, like their own, for they said their rollin' stock was
very heavy, and they wa'n't goin' to take the risk of accidents. The
price of the rails knocked us."
"Naturally," said Truett, "for steel rails were four or six times as
costly then as they are now."
"You've made me too excited to eat," said Philip, leaving the
table, "and I'm afraid that the trouble will continue until this road is
moved from the air to the ground. The main offices of the old
company are only about a hundred miles away; suppose, Truett, that
you and the most truly representative merchant of Claybanks—I
mean Caleb—run up there? I'll look after the men at work on the
store. Tell the president, or whoever is in authority, that we think of
building a spur at once from here to their main track, see what
they'll do, and persuade them to say it in black and white. If they
talk favorably, we'll hold a public meeting, and try to do something.
Mrs. Wright, we owe you an apology. I assure you that business talk
is not the rule at our breakfast table."
"I wish it were!" said Mary, who, with Grace, had listened
excitedly until both women were radiant with enthusiasm. "I wish
railways could be planned at breakfast every day—if my brother
were to be the builder."
"Now, Mary," said Caleb, "perhaps you begin to understand the
Western fever of which I've told you something from time to time."
"Understand it?" said Mary, dashing impulsively at her husband. "I
already have it—madly! I'm willing to bid you good-by at once for
your trip, though I haven't been married a week. My husband a
possible railway director—and yours also, Grace! How do you feel?"
"Prouder than ever," Grace replied. "Just as you will feel, week by
week, as the wife of a clever husband."
XXVI—THE RAILWAY
TRUETT and Caleb were on their way before noon, but not until
Truett had first packed several bricks and fragments of bricks, from
the foundations of the old store, for shipment to New York,
accompanied by a request for probable selling figures of brick of the
same natural quality and properly made. He also wrote for an
estimate of cost of a modest brick-making outfit.
The two men returned within forty-eight hours with a written
promise from the trunk line company to lay the rails, if these and a
proper road-bed were provided, and take stock in payment for the
work; also to take a lease of the road, when completed, by
guaranteeing a six per cent dividend on the stock, which was not to
exceed thirty thousand dollars. The company also imparted the
verbal reminder that a six per cent stock, guaranteed by a sound
company, would always be good security on which to borrow money
from any bank between the Missouri River and the Atlantic Ocean.
"That being the case," said Philip, "I will subscribe all the cash
necessary to purchase the rails, if the road-bed and ties can be
provided according to Truett's plan."
"Don't, Philip!" said Caleb.
"Why not?"
"Because there's such a thing as bein' too big a man in a poor
country, especially if you're a newcomer. Other merchants will
become jealous of you, an' 'twill cause bad feelin' in many ways.
Work public spirit for all it's worth; give ev'rybody a chance; then, if
toward the end there shows up a deficiency, they'll be grateful to
you for makin' it up. Do you want the earth? Quite likely; so
remember what the Bible says, 'The meek shall inherit the earth,' by
which I reckon it doesn't mean the small-spirited, but the men who
don't set their feller-men agin 'em by pushin' themselves too far to
the front. If folks here don't know that you've a lot of money in the
bank in New York, where's the sense of lettin' 'em know it?"
"Right—as usual, Caleb," said Philip, after some impatient pursing
of his lips. "I begin to see, however, in this guaranteed stock—
provided, of course, that the farmers subscribe as freely as Truett's
plan will allow—a way of relieving the stringency of ready money in
this county. We may be able to start a small bank here in the course
of time, especially if any manufacturers can be attracted by the hard
woods, the railway, and the water-power."
"That would realize one o' my oldest an' dearest dreams," said
Caleb, "for 'twould put an end to the farmers' everlastin' grumblin'
about how much worse off they are than the people who have banks
nigh at hand. I don't expect 'em to be much better off—perhaps not
any, for I've noticed that almost any man that can borrow will go on
borrowin' an' spendin', wisely or otherwise, clean up to his limit, an'
then want money just as much as he did at first; but I'd like our
farmers to have the chance to learn it for 'emselves, for I'm very
tired of askin' 'em, for years, to take an honest man's word for it."
Before sunset Philip had called in person on his brother
merchants, Doctor Taggess, the owner of the saw-mill, the county
clerk, and the hotel-keeper, and invited them to meet at his
warehouse-store that evening, immediately after the closing hour,
for a private and confidential talk on a business subject of general
interest to the community. Caleb went into the farming district and
invited a flour miller and several of the more intelligent farmers to
attend the meeting. At the appointed hour every one was present,
the door was locked, Philip briefly outlined the railway scheme, told
of the main line company's offer, and called upon Truett to detail his
plan of construction.
The young engineer responded promptly with facts and figures,
and made much of his proposed stock subscriptions to be paid for in
labor and ties, and the farmers present declared it entirely feasible.
Most of the merchants were frightened at the amount of cash that
would be required for rails, etc., as almost all of it would have to be
subscribed by them; but Philip, backed by the consciousness of his
own bank deposit in the East, assured them that through some
Eastern acquaintances he could get merchants' short notes
discounted for a large part of their subscriptions, and that the
guaranteed stock could be sold or borrowed on as soon as issued; if
the cutting and delivery of ties could begin at once, the road could
be completed soon enough to get the autumn and winter produce to
market almost as rapidly as it could be brought in.
At this stage of the proceedings the owner of the saw-mill
promised to expedite matters by subscribing five hundred dollars'
worth of stock, payable in ties at a fair price. The town's last railway
excitement, several years before, had caused him to buy in a lot of
small timber and saw it into ties, which had been dead stock ever
since; he had even tried to sell them for firewood. Doctor Taggess
thought so highly of the project that he said he would take a
thousand dollars' worth of stock; he had very little ready money, but
through family connections in the East he could raise the money by
mortgaging his home. The county clerk said he would take five
hundred dollars' worth, the hotel-keeper promised to take a similar
amount, and the flour miller asked to be "put down" for two hundred
and fifty. By this time the merchants lifted up their hearts and
pledged enough more to secure the purchase of the metal. It was
then resolved that a public meeting should be held within a week, at
the court-house, roofless though it still was, and all participators in
the private consultation agreed to "boom" the enterprise in the
meantime to the best of their ability.
The public meeting was as enthusiastic and successful as could
have been desired. Caleb had already secured the right of way, as
promised, and a statement of this fact, added to those narrated
above and repeated at the meeting, elicited great applause. Truett
announced the valuations, estimated after much consultation, of the
various kinds of labor to be received in payment of stock; also, the
price of ties, and the length, breadth, thickness, and general quality
of the ties desired. As the required number of ties was apparently in
excess of the producing capacity of the local saw-mill and the
farmers tributary to Claybanks, it was resolved that tie subscriptions
should be solicited from the part of the county on the other side of
the trunk line, and thus expand the blessings of stockholdership.
Then a list of conditional subscriptions was opened, and it filled so
rapidly, that before the meeting adjourned there appeared to be
secured as much labor, money, and ties as would be needed; so a
committee was appointed to organize the Claybanks Railway
Company according to the laws of the state.
"Is it done—really done?" asked Grace and Mary, like two
excitable schoolgirls, when Philip, Caleb, and Truett returned to the
store, which was almost full of expectant farmers' wives.
"It is an accomplished fact—on paper," said Philip. "To that extent
it is done."
"Your own work, you mean," said Truett. "Mine has merely
begun."
"When do you really begin?" asked Mary of her brother.
"To-day—this instant," was the reply, "if I can get a couple of
well-grown boys to assist me, while I go over the route with an
instrument and a lot of stakes."
Several farmers' wives at once offered the services of their own
sons, and went in search of them, while two of the women, more
"advanced" than the others, themselves volunteered to carry stakes,
chains, etc.,—anything to hurry that blessed railroad into existence.
Fortunately the arrival of several boys made the services of these
patriotic ladies unnecessary.
"The sooner I am able to avail myself of any labor that may offer,
the sooner I shall be ready for some of the ties. Oh, those ties! I
wonder how many farmers and their sons I shall have to instruct in
hewing!" said Truett.
"I wouldn't waste any time in thought on that subject, if I were
you," said Caleb; "for what our farmers don't know about hewin'
would take you or any other man a long time to find out. How do
you s'pose all the beams an' standin' timbers of all the houses an'
barns built in this county was made in the days before there were
any saw-mills nearer than twenty miles? How do you s'pose some of
the log houses here are so tight in the joints that they need no
chinkin'? I've heard of some Eastern people bein' born with gold
spoons in their mouths; well, it's just as true that hundreds of
thousands of Westerners were born with axes in their hands. The
axe was their only tool for years, an' they got handy enough with it
to do 'most anythin', from buildin' a house to sharpenin' a lead-
pencil!"
"Good for Caleb!" shouted a farmer's wife, and Truett made haste
to say:—
"I apologize to the entire West, and will put my mind at ease
about the ties."
The subject of conversation was changed by an irruption of
farmers and citizens, who wished to talk more about the new
railroad, and who rightly thought that the place where the engineer
could be found was the most likely source of information. The
questions were almost innumerable, and Truett, who was quite as
excited as any of them, told all he knew about what certain specified
spur roads had done for farming and wooded districts no more
promising than Claybanks; so the informal meeting became even
more enthusiastic than the gathering at the court-house had been,
for the farmers' wives added fuel to the flame. The spectacle
impressed Grace deeply, well though she knew the people; for from
most of the faces was banished, for the time being, the weary,
resigned expression peculiar to a large portion of the farming
population of the newer states. Caleb, too, long though he had
known all the men and women in the throng, had his heart so
entirely in his face that Grace whispered to Mary:—
"Do look at your husband! Did you ever see him look so
handsome, until to-day?"
A strong, warm, nervous hand-clasp was the only reply for a
moment; then Mary whispered:—
"All the men here are fine-looking!—their faces are so expressive!
I've not noticed it until to-day. Where did Claybanks get such
people?"
"Say all that to your husband, if you wish to fill his heart to
overflowing," said Grace, "and then, to please me, repeat it to
Doctor Taggess, or tell both of them at once." To share in the
enjoyment, she succeeded in getting Caleb and the Doctor close to
her and Mary, and quoted to them:—
"'Listen, my children, and you shall hear'—now, Mary!"
"I don't wonder that you're impressed," the Doctor replied, when
Mary's outburst concluded. His own eyes were gleaming, and Mary
said afterward that his face was her ideal of a hero at the moment of
victory.
"Now, Mrs. Somerton, can you again wonder, as you've wondered
aloud to my wife and me, that I, whom you've kindly called a man of
high quality, have been content to pass my adult years among these
backwoods people? Do see their hearts and souls come into their
faces! I know they are not always so, but we never heard of any one
remaining all the while on the Mount of Transfiguration. It isn't the
railway alone that they're thinking of, but of what it will mean to
themselves and their hard-working wives, and to their children,—
closer touch with the great world of which they've read and
wondered, better prices for their yield, which means more creature
comforts at home, better educational facilities for their children, and
less temptation for the children to escape from the farm to the city.
They know that all this must be the work of time, but they've never
before seen the beginning of it, so now they're building air-castles as
rapidly as a lot of magicians in dream-land. I can't blame them, for
I'm doing it myself, old and cautious though I am. They can wait for
the end, so can I; for all of us, out here, have had long training in
the art of waiting. At present the beginning is joy enough, for I can't
imagine how any one about us could look happier."
The formal survey of the railway route began that afternoon, for
the people would listen to no suggestions of delay. It was completed
quickly, and that the company was not yet organized according to
law did not prevent the immediate offer and acceptance of a large
working force of men, boys, horses, etc., from the village itself. The
young engineer was his own entire staff, and also temporary
secretary and accountant of the enterprise; but as it was his first
great job, he enjoyed the irregularity of everything. From that time
forward, for several months, the village stores ceased to be lounging
places. Any villager or farmer with time to spare made his way to the
line of the new road, and feasted his eyes, apparently never to
fulness, on the promise of what was to be.
As the work progressed farther from the town, the farmers of the
vicinity, with their families, would saunter toward the line on Sunday
afternoons and linger for hours, talking of the good times that were
coming, and some of them actually moved their houses as near to
the track as possible, so that the inmates might be able to have the
best possible view of the trains when they began to run. When the
road-bed was made and the ties were placed, and the laying of the
rails began, entire families picnicked for a day at a time beside the
track, although the weather had become cold, merely to see a
shabby locomotive push backward some platform cars loaded with
rails, and to see the rails unloaded, and listen to the musical clamor
of track-laying; for did not each detail of the work bring nearer to
them the hope of Claybanks for a third of a century,—a completed
railway?
Truett had been better than his word. He had promised to finish
the work by Christmas, but the formal opening ceremonies took
place on Thanksgiving Day; and more than half the people of the
county took part in it. With an eye to business the principal
stockholders—the Claybanks merchants—hired a passenger train for
the day, and gave the natives free rides to and from the nearest
station that had a siding and switch by which the train could be sent
back. The station had not a great town to support it,—merely five
thousand people,—but as the Claybankers roamed through the place
and saw many houses finer than any house in Claybanks, several
streets that were paved with wooden blocks and many that had
sidewalks, saw the telegraph and telephone wires, and a bank, and
a fire-engine house, and horse-troughs into which fresh water
flowed steadily from pipes which were part of a general service, their
hearts were filled with the conviction that all these comforts and
conveniences had come through the possession of a railway.
Claybanks was in a fair way to become like unto that town, and they
made haste, each after his kind, to rejoice. Then all of them who
were farmers began to lay out, on their mental tablets, the
appearance of their own farms as they would be when divided into
building lots, and also to count the pleasing sums of money that
would be paid by the purchasers of the lots, and also the many
creature comforts which the money would buy.
The first freight car that left Claybanks for business purposes was
loaded with yellowish brown brick for New York, and all Claybanks
was present to wave hats, handkerchiefs, hands, and aprons, as it
moved slowly off. Claybanks wheat had gone East in times past, so
had Claybanks pork, and undoubtedly these products had entered
into the physical constitution of New York to some extent, but they
could not afterward be identified. Claybanks bricks, however, were
very different. They would be seen by every one, and they would
make Claybanks literally a part of the metropolis itself.
The meaning of all this was felt by the people of all classes; even
Pastor Grateway was so impressed by it that he preached a sermon
from the text, "They shall speak with the enemy in the gates," and
that there should be no doubt as to who "they" were, a brown brick
was at each side of the pulpit for the sides of the open Bible to rest
upon. The pastor, being a man of spiritual insight, did not neglect to
enlarge upon the fact that the bricks themselves were originally clay
—mere earth—that had been trampled underfoot for years,
seemingly useless, until it had been conformed in shape and quality
to the uses for which it had been designed from the foundation of
the world, and that each brick was a reminder that the most
insensate lump of human clay had in it the possibilities for which it
had been created.
Nevertheless, the majority of the hearers only carried home with
them the conviction that the Claybanks brick-yard must become one
of the great things of the world—otherwise, why did the minister
preach about it?
XXVII—CONCLUSION
"CALEB," said Philip one evening, as the partners and their wives
sat in the parlor of the Somerton home and enjoyed the leisure hour
that came between store-closing and bed-time, "so much important
business has been crowded into the past few months that some
smaller ventures have almost escaped my mind. What ever came of
that car-load of walnut stumps that I sent East last summer?"
"I couldn't have told you much about it if you'd asked me a day
earlier," Caleb replied. "I turned it over to a man in the fine-woods
business—a Grand Army comrade that I met at my old chum Jim's
post. He said at the time that the stumps would undoubtedly pay
expenses of diggin' and shipment, an' maybe a lot more, but 'twould
depend entirely on the stumps themselves. He'd have each of 'em
sawed lengthwise an' a surface section dressed, to show the
markings of the grain o' the wood. It seems that they were so
water-soaked that 'twas months after sawin' before the wood of any
of 'em was dry enough to dress, but he got at some of 'em a few
weeks ago, an' though most of 'em wa'n't above the ordinary, there
were two or three that made the furniture an' decoration men bid
against each other at a lively rate. One of 'em panned out over sixty
dollars."
"What? One walnut stump? Sixty dollars?"
"Oh, that's nothing. To work me up, he told me of one, picked up
in the country a few years ago, that brought more than a thousand
dollars to the buyer. The markings were so fine that it was sawn into
thin veneers that were sold for more than their weight in silver. Still,
to come to the point, your entire lot brought about two hundred and
seventy dollars net, an' I've got the check in my pocket to prove it."
"And the land from which they were taken cost me only two
hundred dollars in goods! And there are still hundreds of stumps in
it! And I felt so ashamed and babyish when I learned that I'd been
tricked into buying cleared land, that I almost resolved to recall you
by wire, so that I should be kept from being tricked again in some
similar manner! I shall have to drive out to old Weefer's farm, tell
him the story, and ask him if he has any more walnut clearings for
sale."
"Hadn't you better keep quiet about it? Where's the use in killin'
the goose that lays the golden egg? Pick up all the walnut clearin's
that are for sale, an' make what you can out of 'em, before you go
to talkin'; but if you feel that you must say somethin' on the subject
to somebody, an' jubilate a little, go tell Doc Taggess, who owns the
lot you thought you were buyin'. If anybody deserves to make
money in the boom that's comin', Doc does, an' if he could clear his
land, now that he can railroad the logs to market, an' then get out
his stumps, he might get cash enough ahead to pick up a lot of real
estate, or take stock in millin' enterprises, when the water-power
ditch is made, an' so lay up somethin' to keep him out of the poor-
house in old age; for as long as he can practise, he'll give to the
poor all that he can collect from patients that are better off. The
chap that handled the stumps for you asked me a lot of questions
about the kind an' quantity of standin' timber out here, and said he
didn't see why we didn't start mills to turn out furniture lumber an'
dimension-stuff, like some that have made fortunes for men in the
backwoods of Indiana and Michigan an' some other states."
"Let's try it, if our cash and credit aren't already used as far as
they should be. By the way, how is Claybanks corn-flour, Somerton's
brand, going in England?"
"Fairly. We've sent, in all, about four hundred barrels; that's an
average of a hundred a month, with a net profit to us of about thirty
per cent, which is better, I reckon, than any of the big flour shippers
ever dreamed o' makin'. I've been hopin' that the good tidin's of
good food-stuff at about half the price o' bad would work its way
into other parts of London an' out into the country, too; but English
people don't seem to move about an' swap stories an' prices, like us
Americans. I reckon I came home too soon, for the good o' that
deal, for I had a lot o' things in mind to do in London to make corn-
meal popular. It seems to be the English way to let things alone until
some of the upper classes take to 'em, so I was goin' to try the meal
on some o' the swells; but the more I thought of it, the more it
seemed that they too belonged to the follow-my-leader class. So I
made up my mind to begin way up at the tip-top, an' so I wrote a
letter to Queen Victoria, sayin' I'd come all the way from America to
make the English people practically acquainted with the cheapest
and most nutritious food known in the temperate zone, an' that I
was catchin' on fairly, but the common people seemed to think it
was common stuff, which it wasn't, as I would be glad to prove to
her. Besides, I knew of Americans richer than any nobleman in
England who had it on their tables every day. I said I could make six
kinds o' bread an' three kinds o' puddin' out o' corn-meal, an' I'd like
a chance to do it some day for her own table; if she'd let me do it in
the palace kitchen, I'd bring my own pans an' things, so's not to put
the help to any trouble,—an' I'd—"
"You—wrote—to—the Queen—of England," Philip exclaimed,
"offering to make corn-bread and meal-pudding for the royal table!"
"That's what I did, an' I took pains to specify that 'twould be
made of Claybanks corn-flour, Somerton's brand, too—not the
common meal that again an' again has let down American corn in
foreign minds to the level of the hog-trough. But it didn't work.
Though I put in an addressed postal card for reply, the good lady
never answered my letter. Too busy, I s'pose."
Philip stared at Grace, who pressed one hand closely to her lips,
while Mary looked at her husband as if wondering in what entirely
original and unexpected manner, and where, he might next break
out. Then Philip said gravely:—
"How strange! Besides, I doubt whether any other man was ever
so thoughtful as to enclose a reply-card to her Majesty."
"Well, after waitin' a spell I made up my mind that that particular
cake was all dough. One day when I was in the shop, turnin' sample
cakes an' bread out o' the pans, up drove a carriage, an' a couple o'
well-dressed men, one of 'em short an' stout, an' the other kind o'
tallish, came in an' looked about, kind o' cur'us. 'Try some samples,
gentlemen?' said I, thinkin' they looked as if they was used enough
to good feedin' to know it when they saw it. They nodded, stiffish-
like, an' I set 'em down to a little table with a white cloth on it, an' I
set before 'em dodgers, an' muffins, an' cracklin' bread, an' pan-
cakes, all as hot as red pepper, an' some A 1 English butter to try
'em with—an' they do know how to make butter over in England!
"Well, they sampled 'em all, takin' two or three mouthfuls of each,
an' exchanged opinions, which seemed to be favorable, with their
eyes an' heads. While they were eatin', the shop began to get dark,
an' when I looked around to see if a fog had come up all of a-
sudden, as it sometimes does over there, I saw that the street was
packed with people, an' they were jammed up to the doors an'
windows. 'It's plain that gentlemen are not often on exhibition in this
part of the town,' said I to myself. Suddenly the two got up, an' both
said 'Thanks,' an' went out, an' when their carriage started, the
crowd set up a cheer. 'Who are they?' I said to a man at the door. He
looked at me as if I had tried to run a counterfeit on him, an' he
said, 'Ah, me eye!' but another chap said:—
"'It's the Prince, an' the Duke o' Somethinorother.'"
"H'm! Yet you never got a reply on that postal card!"
"Never. I meant to try again, an' register the letter, so as to be
sure that it got into the right hands, but somethin' kept tellin' me
'twas time to get back home. But if you'll let me make a trip again
next fall, at my own expense, I'll try for better luck. Anyway, I'll work
the corn-meal plan on Liverpool an' other cities, an' if it takes as well
as it's done in London, 'twon't be long before a good many thousan's
of bushels of Claybanks corn'll be saved from the distilleries, in the
course of a year."
"Phil," Grace remarked, "Caleb's wish to go abroad in the fall
reminds me that I want you to take me East for a few weeks in the
spring, and we ought to begin our preparations at once. As 'tis near
Christmas, Mary and I have been talking of presents, and particularly
of one which you and Caleb can join in giving us and at the same
time secure to yourselves more of the business and social
companionship of your wives. We want a housekeeper."
"Sensible women!" Philip replied. "As to your husbands, they will
be delighted—eh, Caleb? If it weren't that servants can't be had in
this part of the country, and help, after the Claybanks manner, would
have banished all sense of privacy, I should think myself a villain of
deepest dye for having allowed the wife of the principal merchant of
Claybanks to cook my meals and do all the remaining work of the
house, and I don't doubt that Caleb feels similarly about Mary."
"Well," said Caleb, "work that wa'n't degradin' to my dear mother
oughtn't to seem too mean for my wife; but, on the other hand, my
mother shouldn't have done it if I could have helped it, 'specially if
she'd have tried also to do a full day's clerk-work in a store once in
ev'ry twenty-four hours."
"That explains our position," Grace added. "You two men are so
full of new business of various kinds that Mary and I should be in the
store all the while. Soon that dreadful pork-house must open for the
season, and then we shall see less of you than ever. A good
housekeeper will cost no more than a good clerk, and we must have
one or the other. We don't want a clerk, if we can avoid it; at
present we have the business entirely in our own hands, and when
there are no customers in the store, we have as much privacy and
freedom as if we were in the house. Mary knows a good woman in
New York who will be glad to come here as maid-of-all-work, if she
may be called housekeeper instead of servant; she has a grown son
who wishes to be a farmer and to begin where land is cheaper and
richer than it is in the vicinity of New York. With such a woman to
care for the house we can spend most of our time in the store, hold
the trade of such womenfolk as deal with us, and try to get the
remainder; for where women and their daughters buy, the husband
and brothers will also go."
"That's as sure as shootin'," said Caleb. "Do you know that in
spite of the cyclone the store has done twice as much business since
you came as it ever did before in the same months? I'd be downright
sorry for the other merchants in town if I didn't believe that we're
soon goin' to have a big increase of population, and there'll be
business enough for all. Philip deserves credit for a lot of the new
business, an' his wife for more, which isn't Philip's fault, but his
fortune in havin' married just that sort of woman. If nobody else'll
say it, I s'pose it won't be presumin' for me to say that a small
percentage of the increase o' the last two or three months has come
through a young woman whose name used to be Mary Truett."
"Small percentage, indeed!" Grace exclaimed. "Mary has secured
more new business than I did in the same number of weeks, and
she has done it so easily, too. She never seems to be thinking of
business when she's talking to a customer, yet she instinctively
knows what each woman wants, and places the proper goods before
her, while I, very likely, would be thinking more of the woman than
of the business."
"That's merely a result of experience," said Mary. "I'm nearly
thirty, with a business experience of ten years; you were a mere chit
of twenty-three when you married. Still, I don't believe any hired
clerk, of no matter how many years' experience, could do half as
well as either of us."
"For the very good reason," said Philip, "that both of you are
practically owners of the business. No clerk can be as useful in any
business as one of the proprietors."
"That remark would 'a' hurt my feelin's, a year ago," said Caleb;
"but since my name went on that sign over the door, I've been
lookin' backward at my old self a lot, an' lookin' down on my old self,
too. Perhaps the difference has come o' gettin' rid o' malaria,
perhaps o' takin' a wife; but I'm goin' to make b'lieve, after makin'
full allowance for ev'rythin' else, that nobody can bring out the best
that's in him until he begins to work for himself."
"No other person would dare criticise your old self in my
presence, Caleb," said Philip, "but you've certainly acquired a new
manner in business, and it's extremely fetching in more senses than
one. One of the best things about it is that the natives notice it, and
talk of it to one another, and are pleased by it, for you're one of
them, you know. I'm a mere outsider."
"Do they really notice it?" asked Caleb, with a suggestion of the
old-time pathos in his face and voice, "an' are they really pleased?
Because, as you say, I'm really one of 'em, an' I'm proud of it. I've
gone through pretty much ev'rythin' they have—'specially the
malaria, an' now that their good times are comin', I'm glad I'm with
'em. But to think—" here he walked deliberately to a mirror and
studied his own face for a moment—"to think that only so little time
ago as when you came here I felt like an old, used-up man, an' I'd
put my house in order, so to speak, against the time when I should
have my last tussle with malaria, an' go under, with the hope o' goin'
upward."
"That was before you met Mary," Grace suggested.
"Yes; that's so."
"And he must get rid of Mary before he can ever have an
opportunity to feel that way again," said the lady referred to, as she
looked proudly at her husband. "Old! Used up! The most spirited,
active, hopeful, cheerful man I ever met! But, really, you were
different, Caleb, when I first saw you; it doesn't seem possible that
you're the same man. From what I've seen of the people here, I
believe it is one of the ways of the West for men to try to look older
than they are; you must use your influence—and example—to make
them stop it. In New York a man seldom looks old until he is very
near the grave; the most active and fine-looking business men are
beyond threescore, as a rule—about twenty years older than you,
Caleb."
"Ye—es, but they weren't brought up on malaria, pork, plough-
handles, an' saleratus biscuit," said Caleb. "There's hope for a
change here, though. Doc Taggess says there's nothin' like as much
malaria in town as there was before the swamps were drained, and
the good times comin', because o' the railroad, 'll make some more
changes for the better, for all of us."
For a few moments each member of the quartet seemed to have
dropped into revery. The silence was broken by Philip, who said:—
"Caleb, a year ago even you would not have dared to prophesy
the changes that have been made, and those which are within sight,
yet to you belongs the credit for all of them."
"To me? Well, I've heard and seen so many amazin' calculations in
the past three months that I'm prepared to stand up under almost
anythin', but I'd like to know how you figure it out that I've done
anythin' in particular."
"'Tis easily told. If you hadn't fallen in love with Miss Truett, and
she with you, her brother wouldn't have come out here, and the
malaria wouldn't have been drained from the swamps, and the
railway wouldn't have been projected, and the farmers wouldn't
have become owners of guaranteed stocks, which has put new life
into many of them, and there'd have been no inducement for
manufacturers to use our water-power and our hard woods, and no
bank would have been possible, nor any of the public improvements,
—paving, water service, and others that will soon be under way.
Don't you see?"
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like