Effective Ruby
@EffectiveRuby
A book from the Effective Software Development Series, written by @contextualdev, published by Addison-Wesley Professional, September 25, 2014.
You might like
Friends don't let friends write method_missing.
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…
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!
.@hexforfun sure, you can hack Class.new. Just don't let me see this code end up in production! gist.github.com/pjones/fddae91…
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.
United States Trends
- 1. Belichick N/A
- 2. Nebraska N/A
- 3. Michigan N/A
- 4. Staged N/A
- 5. #WWENXT N/A
- 6. Bill Polian N/A
- 7. Hall of Fame N/A
- 8. Palat N/A
- 9. Brady N/A
- 10. Ilhan Omar N/A
- 11. Rutgers N/A
- 12. #iubb N/A
- 13. #DelcyLaVozDeLaPaz N/A
- 14. #WonderMan N/A
- 15. Spygate N/A
- 16. Tillis N/A
- 17. HOFer N/A
- 18. J Cole N/A
- 19. Mast N/A
- 20. Gruden N/A
You might like
-
RubyConf
@rubyconf -
RubyMine, a JetBrains IDE
@rubymine -
Marcia Villalba 🦄
@mavi888uy -
RustConf
@rustconf -
mausimus
@mausmoto -
fabcross
@fabcrossjp -
プロ散財家 どりきん
@drikin -
Nate Berkopec
@nateberkopec -
ScanNetSecurity
@ScanNetSecurity -
バーチャルキャスト@VirtualCast
@virtual_cast -
Rafael França 🇧🇷
@rafaelfranca -
usagimaru ⌘
@usagimaruma -
Vinicius Senger
@siliconvini -
Josh Software
@joshsoftware -
k0kubun
@k0kubun
Something went wrong.
Something went wrong.