Ruby Best Practices

Ruby Best Practices

Language: English

Pages: 336

ISBN: 0596523009

Format: PDF / Kindle (mobi) / ePub

Ruby Best Practices

Language: English

Pages: 336

ISBN: 0596523009

Format: PDF / Kindle (mobi) / ePub


How do you write truly elegant code with Ruby? Ruby Best Practices is for programmers who want to use Ruby as experienced Rubyists do. Written by the developer of the Ruby project Prawn, this concise book explains how to design beautiful APIs and domain-specific languages with Ruby, as well as how to work with functional programming ideas and techniques that can simplify your code and make you more productive. You'll learn how to write code that's readable, expressive, and much more.

Ruby Best Practices will help you:

  • Understand the secret powers unlocked by Ruby's code blocks
  • Learn how to bend Ruby code without breaking it, such as mixing in modules on the fly
  • Discover the ins and outs of testing and debugging, and how to design for testability
  • Learn to write faster code by keeping things simple
  • Develop strategies for text processing and file management, including regular expressions
  • Understand how and why things can go wrong
  • Reduce cultural barriers by leveraging Ruby's multilingual capabilities

This book also offers you comprehensive chapters on driving code through tests, designing APIs, and project maintenance. Learn how to make the most of this rich, beautiful language with Ruby Best Practices.

Swift for Beginners

Modeling Derivatives in C++ (Wiley Finance)

iPhone and iPad Apps for Absolute Beginners (4th Edition)

Ace the Programming Interview: 160 Questions and Answers for Success

Software Testing

Masterminds of Programming: Conversations with the Creators of Major Programming Languages

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Ruby’s Standard Library APPENDIX C Ruby Worst Practices If you’ve read through most of this book, you’ll notice that it doesn’t have much of a “Do this, not that” theme. Ruby as a language doesn’t fit well into that framework, as there are always exceptions to any rule you can come up with. However, there are certainly a few things you really shouldn’t do, unless you know exactly why you are doing them. This appendix is meant to cover a handful of those scenarios and show you some better

Points may be specified as [x1,y1], [x2,y2] or x1,y1,x2,y2 ... >> distance3 [3,3,3,4] ArgumentError: Points may be specified as [x1,y1], [x2,y2] or x1,y1,x2,y2 ... >> distance3 [3,3],[3,4] => 1.0 >> distance3 3,3,3,4 => 1.0 Ruby’s Secret Power: Flexible Argument Processing | 39 Though this may be a more robust way to write the method, it is more complicated. Playing fast and loose might not be a bad thing if you can expect your users to provide sane input. The following version is the

already discussed covers most of what you’ll need day to day, so now is a fine time to go over what’s been said and move on to the next thing. We’ve gone over some of the tools Ruby provides for working with your filesystem in a platform-agnostic way, and we’re about to get into some more advanced strategies for managing, processing, and manipulating your files and their contents. However, before we do that, let’s review the key points about working with your filesystem and with temp

hood. The underlying idea here is simple, though. You can clean up your code significantly by identifying the points where encodings matter in your code. Oftentimes, there will be a handful of low-level functions that are at the core of your system, and they are the places where transcoding needs to be done. In the case of Prawn, even with things like formatted text boxes and tables and other fancy means of putting content on the page, the core method that is used by all of those features

to remain unmodified. The second view is a bit easier because, as mentioned before, it’s strictly displaying information: <% translated do %>

<%= T("You", :you) %>: <%= weapon_name(@player_weapon) %>

<%= T("Opponent", :opponent) %>: <%= weapon_name(@opponent_weapon) %>

<%= end_game_message %>

<% end %> Here, we’re just looking up a few more tagged

Download sample

Download