SlideShare a Scribd company logo
1 of 3
Download to read offline
Version 0.1



                      A Little Ruby, A Lot of Objects
Preface
Welcome to my little book. In it, my goal is to teach you a way to think about
computation, to show you how far you can take a simple idea: that all computation
consists of sending messages to objects. Object-oriented programming is no longer
unusual, but taking it to the extreme – making everything an object – is still supported by
only a few programming languages.

Can I justify this book in practical terms? Will reading it make you a better programmer,
even if you never use "call with current continuation" or indulge in "metaclass hackery"?
I think it might, but perhaps only if you're the sort of person who would read this sort of
book even if it had no practical value.

The real reason for reading this book is that the ideas in it are neat. There's an intellectual
heritage here, a history of people building idea upon idea. It's an academic heritage, but
not in the fussy sense. It's more a joyous heritage of tinkerers, of people buttonholing
their friends and saying, "You know, if I take that and think about it like this, look what I
can do!"

Prerequisites

With effort, someone who didn't know programming could read this book. I expect that
most readers will know at least one programming language, not necessarily an object-
oriented one.

I use a few simple mathematical ideas in some of the examples. The factorial function is
the most complex, and I explain a simplified form of it, rather than assume you know
what it is. I don't think the book requires any particular mathematical inclination, so don't
be scared off at the first sight of factorial.

Using the book
This book is written as a dialogue between two people, one who knows objects well, and
one who doesn't. The text builds cumulatively. If you don't understand something about
one chapter, you'll likely understand the next chapter even less. So I recommend you read
slowly. The characters in the book take frequent breaks. I think that's a good idea.

This book uses Ruby, a freely available language developed by Yukihiro Matsumoto, but
it is not a book about Ruby. Ruby constructs are introduced gradually, as they're needed,
rather than in any systematic order. They're described only enough to allow you to
understand code that contains them.

If you want to try variants of the examples, you may need a little more Ruby knowledge.
The example files (see below) define new constructs a little more completely. However,

                 Copyright © 2001 by Brian Marick. All Rights Reserved.
DRAFT                       (marick@visibleworkings.com)                               DRAFT
even with the examples, this book is not a Ruby tutorial. If you want to use Ruby for
general-purpose programming – and you should, since it's a wonderful rapid-
development language for many types of applications - the book to read is Programming
Ruby, by David Thomas and Andrew Hunt (available online at
www.rubycentral.com/book/index.html). You'll find that Ruby has many more features
than this book describes.

Notation

Ruby text and values printed by the Ruby interpreter are in italic font. Everything else is
in normal font. Important terms are in bold when they're defined.

Sometimes, one participant will show a partially completed snippet of Ruby code. The
unfinished part is indicated with ???:

      def finish_this
        ???
      end

Bold italic font is used to draw your attention to a part of some Ruby code

      class Something
        def some_function
          "look here"
        end
      end

Running the examples

I recommend you play with the examples as you read.

As of this writing, Ruby works on Unix and Windows. It is available from www.ruby-
lang.org. The Windows download comes from www.rubycentral.com, at
www.rubycentral.com/downloads/ruby-install.html.

I recommend you use the Ruby interpreter irb. Here's an example:

       > irb
       irb(main):001:0> 1 + 1
       2
       irb(main):002:0>

All of the examples in the book are available from www.visibleworkings.com/little-
ruby/source. At the points in the text where an example is complete, a marginal note
names the example's file:




DRAFT                                         2                                     DRAFT
Exactly. What do you suppose this Ruby             The name tells me it computes factorial,
function does?                                     but I’ not sure how.
                                                         m

        def factorial(n)
          if n == 1
             n
          else
             n * factorial(n-1)
          end
        end

ch1-factorial.rb


You can either cut and paste the example into irb, or load the example into Ruby like
this:

          > irb
          irb(main):001:0> load 'ch1-factorial.rb'
          true
          irb(main):002:0>

(This assumes you're running irb in the directories where the examples live.) Thereafter,
you can type things like this:

          irb(main):002:0> factorial 5
          120
          irb(main):003:0>

Acknowledgements
This book was inspired by The Little Lisper, by Daniel P. Friedman and Mattthias
Felleisen. I fell in love with their book around 1984. The fourth edition, titled The Little
Schemer, is still available. If you like this book, you'll like that one too, especially
because it treats computation from a different perspective.

The Little Lisper is famous for using food in its examples. As the authors say, "[it] is not
a good book to read while dieting." As an ironic homage to my inspiration, one of the
characters here is an exercise freak. In that way, this is a very different book.

I received help and encouragement from people who read drafts: Al Chou, Mikkel
Damsgaard, Joani DiSilvestro, Pat Eyler, Darrell Ferguson, Tammo Freese, Hal E.
Fulton, Ned Konz, Dragos A. Manolescu, Dawn Marick, Pete McBreen, Nat Pryce,
Christopher Sawtell, Kevin Smith, Dave Thomas, David Tillman, and Eugene
Wallingford.




DRAFT                                          3                                      DRAFT

More Related Content

Similar to FrontMatter

ruby_vs_perl_and_python
ruby_vs_perl_and_pythonruby_vs_perl_and_python
ruby_vs_perl_and_pythontutorialsruby
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorialknoppix
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic RevisitedAdam Keys
 
Naming Things (with notes)
Naming Things (with notes)Naming Things (with notes)
Naming Things (with notes)Pete Nicholls
 
Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)Karel Minarik
 
Documentation for developers
Documentation for developersDocumentation for developers
Documentation for developersMichael Marotta
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Rormyuser
 
Computers for-smart-people
Computers for-smart-peopleComputers for-smart-people
Computers for-smart-peopleKing Mj
 
On the path to become a jr. developer short version
On the path to become a jr. developer short versionOn the path to become a jr. developer short version
On the path to become a jr. developer short versionAntonelo Schoepf
 
Invasion of the dynamic language weenies
Invasion of the dynamic language weeniesInvasion of the dynamic language weenies
Invasion of the dynamic language weeniesSrijit Kumar Bhadra
 
Avoid adding a new library to the project
Avoid adding a new library to the projectAvoid adding a new library to the project
Avoid adding a new library to the projectPVS-Studio
 
The Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl SeguinThe Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl SeguinPaulo Fagundes
 

Similar to FrontMatter (20)

ruby_vs_perl_and_python
ruby_vs_perl_and_pythonruby_vs_perl_and_python
ruby_vs_perl_and_python
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
 
Book of ruby
Book of rubyBook of ruby
Book of ruby
 
Naming Things (with notes)
Naming Things (with notes)Naming Things (with notes)
Naming Things (with notes)
 
Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)
 
Documentation for developers
Documentation for developersDocumentation for developers
Documentation for developers
 
On lisp
On lispOn lisp
On lisp
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
Computers for-smart-people
Computers for-smart-peopleComputers for-smart-people
Computers for-smart-people
 
On the path to become a jr. developer short version
On the path to become a jr. developer short versionOn the path to become a jr. developer short version
On the path to become a jr. developer short version
 
Naming Things
Naming ThingsNaming Things
Naming Things
 
Mongodb
MongodbMongodb
Mongodb
 
Ruby
RubyRuby
Ruby
 
Ruby
RubyRuby
Ruby
 
The Bund language
The Bund languageThe Bund language
The Bund language
 
Invasion of the dynamic language weenies
Invasion of the dynamic language weeniesInvasion of the dynamic language weenies
Invasion of the dynamic language weenies
 
Avoid adding a new library to the project
Avoid adding a new library to the projectAvoid adding a new library to the project
Avoid adding a new library to the project
 
Thinkapjava
ThinkapjavaThinkapjava
Thinkapjava
 
The Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl SeguinThe Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl Seguin
 

More from tutorialsruby

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

FrontMatter

  • 1. Version 0.1 A Little Ruby, A Lot of Objects Preface Welcome to my little book. In it, my goal is to teach you a way to think about computation, to show you how far you can take a simple idea: that all computation consists of sending messages to objects. Object-oriented programming is no longer unusual, but taking it to the extreme – making everything an object – is still supported by only a few programming languages. Can I justify this book in practical terms? Will reading it make you a better programmer, even if you never use "call with current continuation" or indulge in "metaclass hackery"? I think it might, but perhaps only if you're the sort of person who would read this sort of book even if it had no practical value. The real reason for reading this book is that the ideas in it are neat. There's an intellectual heritage here, a history of people building idea upon idea. It's an academic heritage, but not in the fussy sense. It's more a joyous heritage of tinkerers, of people buttonholing their friends and saying, "You know, if I take that and think about it like this, look what I can do!" Prerequisites With effort, someone who didn't know programming could read this book. I expect that most readers will know at least one programming language, not necessarily an object- oriented one. I use a few simple mathematical ideas in some of the examples. The factorial function is the most complex, and I explain a simplified form of it, rather than assume you know what it is. I don't think the book requires any particular mathematical inclination, so don't be scared off at the first sight of factorial. Using the book This book is written as a dialogue between two people, one who knows objects well, and one who doesn't. The text builds cumulatively. If you don't understand something about one chapter, you'll likely understand the next chapter even less. So I recommend you read slowly. The characters in the book take frequent breaks. I think that's a good idea. This book uses Ruby, a freely available language developed by Yukihiro Matsumoto, but it is not a book about Ruby. Ruby constructs are introduced gradually, as they're needed, rather than in any systematic order. They're described only enough to allow you to understand code that contains them. If you want to try variants of the examples, you may need a little more Ruby knowledge. The example files (see below) define new constructs a little more completely. However, Copyright © 2001 by Brian Marick. All Rights Reserved. DRAFT (marick@visibleworkings.com) DRAFT
  • 2. even with the examples, this book is not a Ruby tutorial. If you want to use Ruby for general-purpose programming – and you should, since it's a wonderful rapid- development language for many types of applications - the book to read is Programming Ruby, by David Thomas and Andrew Hunt (available online at www.rubycentral.com/book/index.html). You'll find that Ruby has many more features than this book describes. Notation Ruby text and values printed by the Ruby interpreter are in italic font. Everything else is in normal font. Important terms are in bold when they're defined. Sometimes, one participant will show a partially completed snippet of Ruby code. The unfinished part is indicated with ???: def finish_this ??? end Bold italic font is used to draw your attention to a part of some Ruby code class Something def some_function "look here" end end Running the examples I recommend you play with the examples as you read. As of this writing, Ruby works on Unix and Windows. It is available from www.ruby- lang.org. The Windows download comes from www.rubycentral.com, at www.rubycentral.com/downloads/ruby-install.html. I recommend you use the Ruby interpreter irb. Here's an example: > irb irb(main):001:0> 1 + 1 2 irb(main):002:0> All of the examples in the book are available from www.visibleworkings.com/little- ruby/source. At the points in the text where an example is complete, a marginal note names the example's file: DRAFT 2 DRAFT
  • 3. Exactly. What do you suppose this Ruby The name tells me it computes factorial, function does? but I’ not sure how. m def factorial(n) if n == 1 n else n * factorial(n-1) end end ch1-factorial.rb You can either cut and paste the example into irb, or load the example into Ruby like this: > irb irb(main):001:0> load 'ch1-factorial.rb' true irb(main):002:0> (This assumes you're running irb in the directories where the examples live.) Thereafter, you can type things like this: irb(main):002:0> factorial 5 120 irb(main):003:0> Acknowledgements This book was inspired by The Little Lisper, by Daniel P. Friedman and Mattthias Felleisen. I fell in love with their book around 1984. The fourth edition, titled The Little Schemer, is still available. If you like this book, you'll like that one too, especially because it treats computation from a different perspective. The Little Lisper is famous for using food in its examples. As the authors say, "[it] is not a good book to read while dieting." As an ironic homage to my inspiration, one of the characters here is an exercise freak. In that way, this is a very different book. I received help and encouragement from people who read drafts: Al Chou, Mikkel Damsgaard, Joani DiSilvestro, Pat Eyler, Darrell Ferguson, Tammo Freese, Hal E. Fulton, Ned Konz, Dragos A. Manolescu, Dawn Marick, Pete McBreen, Nat Pryce, Christopher Sawtell, Kevin Smith, Dave Thomas, David Tillman, and Eugene Wallingford. DRAFT 3 DRAFT