Ruby最佳实践(影印版)
Ruby最佳实践(影印版)
Gregory T. Brown
出版时间:2009年12月
页数:309
你能够编写真正优雅的Ruby代码吗?《Ruby最佳实践》正是为想要像专家那样使用Ruby的程序员所准备的。本书由Ruby项目Prawn的开发者所著,简洁地向你阐释如何使用Ruby编写优美的应用程序接口和领域特定语言。此外,还包括如何应用函数式编程的思想和技术,使代码更简洁,使你更有效率。通过本书,你将会学到如何编写可读性更高,表达能力更强的代码,以及许多其他方面的内容。
《Ruby最佳实践》将会帮助你:
* 理解Ruby代码块所蕴含的神秘力量
* 学习如何在不破坏原有Ruby代码的情况下进行调整,例如运行时在模块内糅合
* 探究测试与调试中的细节,以及如何从易测性出发进行设计
* 学习通过让事情保持简单来编写快速代码
* 用于文本处理和文件管理的开发策略,包括正则表达式
* 理解为什么会发生错误以及错误是如何发生的
* 利用Ruby的多语言特性减少文化障碍
本书还包含多个章节对测试代码、设计应用程序接口以及项目维护做了全面介绍。《Ruby最佳实践》将陪伴你学习如何将这门丰富、优美的语言发挥到极致。
“这是一本极为务实的著作,各层次的开发人员都能从中借鉴。”
——Brad Ediger,Madriska Media Group的领袖开发者,同时也是《Advanced Rails》(O'Reilly)的作者
“终于有这样一本书问世了,它不仅教我如何使用Ruby,更教会我如何正确地使用它。每位Ruby爱好者的书架上都该摆上一本《Ruby最佳实践》。”
——Jeremy McAnally,ENTP开发者,同时还是《Ruby in Practice》(Manning)一书的作者
“我敢打赌,通过阅读这本书,你一定学到了可以提高Ruby编程能力的新技巧。”
——James Edward Gray II,代码忍者及Ruby 1.9 的CSV标准库的作者
Gregory T. Brown是康涅狄格州纽黑文市的一位Ruby爱好者,他的大多数时间都花在了与Ruby语言相关的自由软件项目上。他是Ruport的原作者,并且是Prawn的作者,该Ruby库被用来生成PDF文档。
Ruby语言创造者松本行弘为本书作序。
  1. Foreword
  2. Preface
  3. 1. Driving Code Through Tests
  4. A Quick Note on Testing Frameworks
  5. Designing for Testability
  6. Testing Fundamentals
  7. Well-Focused Examples
  8. Testing Exceptions
  9. Run the Whole Suite at Once
  10. Advanced Testing Techniques
  11. Using Mocks and Stubs
  12. Testing Complex Output
  13. Keeping Things Organized
  14. Embedding Tests in Library Files
  15. Test Helpers
  16. Custom Assertions
  17. Conclusions
  18. 2. Designing Beautiful APIs
  19. Designing for Convenience: Ruport’s Table( ) feature
  20. Ruby’s Secret Power: Flexible Argument Processing
  21. Standard Ordinal Arguments
  22. Ordinal Arguments with Optional Parameters
  23. Pseudo-Keyword Arguments
  24. Treating Arguments As an Array
  25. Ruby’s Other Secret Power: Code Blocks
  26. Working with Enumerable
  27. Using Blocks to Abstract Pre- and Postprocessing
  28. Blocks As Dynamic Callbacks
  29. Blocks for Interface Simplification
  30. Avoiding Surprises
  31. Use attr_reader, attr_writer, and attr_accessor
  32. Understand What method? and method! Mean
  33. Make Use of Custom Operators
  34. Conclusions
  35. 3. Mastering the Dynamic Toolkit
  36. BlankSlate: A BasicObject on Steroids
  37. Building Flexible Interfaces
  38. Making instance_eval( ) Optional
  39. Handling Messages with method_missing( ) and send( )
  40. Dual-Purpose Accessors
  41. Implementing Per-Object Behavior
  42. Extending and Modifying Preexisting Code
  43. Adding New Functionality
  44. Modification via Aliasing
  45. Per-Object Modification
  46. Building Classes and Modules Programmatically
  47. Registering Hooks and Callbacks
  48. Detecting Newly Added Functionality
  49. Tracking Inheritance
  50. Tracking Mixins
  51. Conclusions
  52. 4. Text Processing and File Management
  53. Line-Based File Processing with State Tracking
  54. Regular Expressions
  55. Don’t Work Too Hard
  56. Anchors Are Your Friends
  57. Use Caution When Working with Quantifiers
  58. Working with Files
  59. Using Pathname and FileUtils
  60. The tempfile Standard Library
  61. Automatic Temporary Directory Handling
  62. Collision Avoidance
  63. Same Old I/O Operations
  64. Automatic Unlinking
  65. Text-Processing Strategies
  66. Advanced Line Processing
  67. Atomic Saves
  68. Conclusions
  69. 5. Functional Programming Techniques
  70. Laziness Can Be a Virtue (A Look at lazy.rb)
  71. Minimizing Mutable State and Reducing Side Effects
  72. Modular Code Organization
  73. Memoization
  74. Infinite Lists
  75. Higher-Order Procedures
  76. Conclusions
  77. 6. When Things Go Wrong
  78. A Process for Debugging Ruby Code
  79. Capturing the Essence of a Defect
  80. Scrutinizing Your Code
  81. Utilizing Reflection
  82. Improving inspect Output
  83. Finding Needles in a Haystack
  84. Working with Logger
  85. Conclusions
  86. 7. Reducing Cultural Barriers
  87. m17n by Example: A Look at Ruby’s CSV Standard Library
  88. Portable m17n Through UTF-8 Transcoding
  89. Source Encodings
  90. Working with Files
  91. Transcoding User Input in an Organized Fashion
  92. m17n in Standalone Scripts
  93. Inferring Encodings from Locale
  94. Customizing Encoding Defaults
  95. m17n-Safe Low-Level Text Processing
  96. Localizing Your Code
  97. Conclusions
  98. 8. Skillful Project Maintenance
  99. Exploring a Well-Organized Ruby Project (Haml)
  100. Conventions to Know About
  101. What Goes in a README
  102. Laying Out Your Library
  103. Executables
  104. Tests
  105. Examples
  106. API Documentation via RDoc
  107. Basic Documentation Techniques and Guidelines
  108. Controlling Output with RDoc Directives
  109. The RubyGems Package Manager
  110. Writing a Gem::Specification
  111. Working with Dependencies
  112. Rake: Ruby’s Built-in Build Utility
  113. Conclusions
  114. A. Writing Backward-Compatible Code
  115. B. Leveraging Ruby’s Standard Library
  116. C. Ruby Worst Practices
  117. Index
书名:Ruby最佳实践(影印版)
作者:Gregory T. Brown
国内出版社:东南大学出版社
出版时间:2009年12月
页数:309
书号:978-7-5641-1935-5
原版书出版商:O'Reilly Media
Gregory T. Brown
 
Gregory Brown is a New Haven, Connecticut-based Rubyist who spends most of his
time on free software projects in Ruby. His main projects are Prawn and Ruport. He
also is in possession of a small bamboo plant that seems to be invincible, and he is quite
proud of this accomplishment.
 
 
The animal on the cover of Ruby Best Practices is a green crab (Carcinus maenas). Also
known as a European shore crab, it is native to the coasts of the North and Baltic Seas.
Although relatively small—adults measure three inches across—an adult green crab
can consume up to 40 clams each day and can eat other crabs as large as itself. A
voracious predator, the green crab also preys on oysters, mussels, and snails,
competing for food with many fish and bird species.
Despite its name, the green crab’s shell color can vary from dark green to orange or red,
sometimes with yellow patches on its underside. The abdomen of the male is triangular
in shape, whereas the female’s is broader and rounder. Males and females also react
differently upon being picked up: males typically stretch out their legs, whereas females
fold them in, a behavior known as the egg-protection reflex.
A natural colonizer, the green crab is potentially destructive to any ecosystem it invades.
It has already invaded many coastal communities outside of its native range, including
Australia, South Africa, and North America, where it is blamed for the collapse of the
softshell clam industry in Maine. It is ranked number 18 on the list of the 100 world’s
worst invasive types of species. Numerous efforts around the world have been made to
control invading populations, to varying degrees of success. One of the more effective
experiments has been on Martha’s Vineyard, Massachusetts, where the town of
Edgartown pays bounty hunters 40 cents per pound of green crab; more than 10 tons
have been caught and destroyed as a result.
购买选项
定价:48.00元
书号:978-7-5641-1935-5
出版社:东南大学出版社