Hasty Briefsbeta

The Unofficial Ruby Usage Guide

2 days ago
  • #Style Guide
  • #Ruby
  • #Programming
  • The document was originally written for internal use at Google's Operations department to advocate for Ruby's acceptance by providing a style and usage guide.
  • Ruby is highlighted as an excellent tool for system administration and other tasks, promoting a common stylistic vocabulary for easier code maintenance and readability.
  • Interactive Ruby (irb) is recommended for development, offering features like method name completion and automatic result printing to speed up the edit-run-debug cycle.
  • Ruby Interactive (ri) is introduced as a documentation tool similar to perldoc, essential for accessing Ruby's class and method documentation.
  • The Ruby debugger and benchmarking module are mentioned as crucial tools for debugging and performance optimization, respectively.
  • Unit testing with Ruby's Test::Unit module is emphasized for verifying code correctness, with an example provided from the Ruby/Password library.
  • Editor support for Ruby in Vim and Emacs is briefly mentioned, highlighting syntax highlighting and Ruby interpreter integration in Vim.
  • Stylistic guidelines for Ruby coding are outlined, including code organization, exception handling, avoiding global variables, and the importance of consistent indentation and whitespace.
  • Documentation practices using RDoc are encouraged for self-documenting code, with tips on commenting and the use of RD for headers or footers.
  • String handling, operator precedence, and iterator block syntax are discussed, along with recommendations for using newer libraries over deprecated ones.
  • Naming conventions for classes, modules, constants, methods, and variables are specified to maintain consistency across Ruby codebases.
  • Safe levels in Ruby are introduced as a means to enhance security when handling untrusted data, with four levels of increasing security described.
  • The document concludes by advocating for pure Ruby solutions over calling external binaries to avoid security, robustness, and portability risks, and emphasizes the importance of coding consistency.