EffectiveRuby's profile picture. A book from the Effective Software Development Series, written by @contextualdev, published by Addison-Wesley Professional, September 25, 2014.

Effective Ruby

@EffectiveRuby

A book from the Effective Software Development Series, written by @contextualdev, published by Addison-Wesley Professional, September 25, 2014.

Pinned

Friends don't let friends write method_missing.


Effective Ruby reposted

Free open source contribution idea: clone your favorite rubygem, run `RUBYOPT="-w" bundle exec rake`. Emit any warnings? Fix 'em!


Avoid using Time::now in #ruby tests. Prefer using Time::parse with a fixed date to prevent inadvertent time dependencies.


New versions of Ruby 1.9, 2.0, 2.1, and 2.2 due to a security patch: ruby-lang.org/en/news/2015/1…


Watch out for the unusual argument evaluation rules with the new safe navigation operator in Ruby 2.3: gist.github.com/pjones/dc6157e…


Effective Ruby reposted

Protected methods are designed to share private info between related classes - @EffectiveRuby


The `return' keyword isn't used very often in #Ruby. Don't be afraid of it! In many situations it can improve the readability of your code.


Have a Ruby tip that you want to share? Send it to me and I'll RT. Same with questions. I'll try to answer the good ones with a tweet/gist.


CGI.escape and URI.escape do different things and have bugs. Use the addressable gem instead. Addressable should replace URI in #ruby core!


Mocking can be useful. Just remember, mocking and hijacking can lead to untested code, possibly containing bugs, that will go unnoticed.


Don't eval strings! Use Ruby's rich metaprogramming features such as define_method and the *_exec methods. Use of eval will result in shame.


Keep exception handling code small and simple. Don't rescue exceptions just to ignore them. Rescue the specific exceptions you can handle.


Unless you are using Ruby 1.8, don't explicitly require "rubygems". If you're still using Ruby 1.8 you should consider your life choices.


Want to know how many arguments a block/proc/lambda expects? Use Proc#arity. Just be sure to read the docs, it can return negative values.


In any nontrivial code you should use modules to create namespaces for classes, constants, etc. Classes also create namespaces, FYI.


We've all been bitten by mutating an argument and forgetting that changes are visible elsewhere. Understand why: bit.ly/1A5RCSz


Think true and false are keywords? Guess again. They're more like global variables: true.object_id # => 20 TRUE.object_id # => 20


Using method_missing to expose a Hash's keys as methods? Stop. It's embarrassing. Use Struct, OpenStruct, or write a class instead.


Singleton classes are so named because they belong to only one object.


Until you can predict the future, always include upper bounds on version numbers in your Gemfile/gemspec.


This account does not follow anyone
Loading...

Something went wrong.


Something went wrong.