没有合适的资源?快使用搜索试试~ 我知道了~
Programming Ruby 1.9 3rd edition
5星 · 超过95%的资源 需积分: 10 240 下载量 40 浏览量
2010-11-12
19:32:19
上传
评论 3
收藏 7.17MB PDF 举报
温馨提示
试读
916页
Programming Ruby 1.9 3rd edition.Cover ruby 1.9.2, downloaded from pragmatic bool shelf, please enjoy.
资源推荐
资源详情
资源评论
Prepared exclusively for ikej
Programming Ruby 1.9
The Pragmatic Programmers’ Guide
Dave Thomas
with
Chad Fowler
Andy Hunt
The Pragmatic Bookshelf
Raleigh, North Carolina Dallas, Texas
Prepared exclusively for ikej
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 Pragmatic Programmers, LLC was aware of a trademark claim,
the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic
Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic
Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors
or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more
fun. For more information, as well as the latest Pragmatic titles, please visit us at
http://www.pragprog.com.
Copyright
©
2010 The Pragmatic Programmers, LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any me ans,
electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN-10: 1-934356-08-5
ISBN-13: 978-1-934356-08-1
Printed on acid-free paper.
3.0 printing, November 2010
Version: 2010-11-9
Prepared exclusively for ikej
Contents
Foreword 11
Preface 12
Why Ruby? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Ruby Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Changes in the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Notation Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Road Map 17
I Facets of Ruby 19
1 Getting Started 20
1.1 The Command Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.2 Installing Ruby . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.3 Running Ruby . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
1.4 Ruby Documentation: RDoc and ri . . . . . . . . . . . . . . . . . . . 29
2 Ruby.new 32
2.1 Ruby Is an Object-Oriented Language . . . . . . . . . . . . . . . . . . 32
2.2 Some Basic Ruby . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.3 Arrays and Hashes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.4 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.5 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.6 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.7 Blocks and Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.8 Reading and ’Riting . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
2.9 Command-Line Arguments . . . . . . . . . . . . . . . . . . . . . . . 46
2.10 Onward and Upward . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Prepared exclusively for ikej
CONTENTS 5
3 Classes, Objects, and Variables 47
3.1 Objects and Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.2 Classes Working with Other Classes . . . . . . . . . . . . . . . . . . . 55
3.3 Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.4 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4 Containers, Blocks, and Iterators 63
4.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.2 Hashes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
4.3 Blocks and Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.4 Containers Everywhere . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5 Sharing Functionality: Inheritance, Modules, and Mixins 86
5.1 Inheritance and Messages . . . . . . . . . . . . . . . . . . . . . . . . 86
5.2 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.3 Mixins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.4 Iterators and the Enumerable Module . . . . . . . . . . . . . . . . . . 95
5.5 Composing Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
5.6 Inheritance, Mixins, and Design . . . . . . . . . . . . . . . . . . . . . 98
6 Standard Types 100
6.1 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
6.2 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
6.3 Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7 Regular Expressions 111
7.1 What Regular Expressions Let You Do . . . . . . . . . . . . . . . . . 111
7.2 Ruby’s Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . 112
7.3 Digging Deeper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
7.4 Advanced Regular Expressions . . . . . . . . . . . . . . . . . . . . . 123
8 More About Methods 131
8.1 Defining a Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
8.2 Calling a Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
9 Expressions 139
9.1 Operator Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
9.2 Miscellaneous Expressions . . . . . . . . . . . . . . . . . . . . . . . . 141
9.3 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
9.4 Conditional Execution . . . . . . . . . . . . . . . . . . . . . . . . . . 146
9.5 case Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
9.6 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9.7 Variable Scope, Loops, and Blocks . . . . . . . . . . . . . . . . . . . 156
Report erratum
this copy is (3.0 printing, November 2010)
Prepared exclusively for ikej
剩余915页未读,继续阅读
book_iike22
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页