Created
February 16, 2011 10:03
-
-
Save rmoriz/829122 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # bad | |
| # | |
| def calculate(string_or_array) | |
| if !string_or_array.is_a?(Array) | |
| string_or_array = [ string_to_array ] | |
| end | |
| … | |
| end | |
| # good | |
| # | |
| def calculate(string_or_array) | |
| array = Array string_or_array | |
| … | |
| end | |
| # nb: Kernel.Array is the new .to_a | |
| # ruby-1.8.7-p302 :018 > Array "123" | |
| # => ["123"] | |
| # ruby-1.8.7-p302 :019 > Array %w(auto bahn hubschrauber) | |
| # => ["auto", "bahn", "hubschrauber"] | |
| # ruby-1.8.7-p302 :020 > Array "internetheld" | |
| # => ["internetheld"] | |
| # ruby-1.8.7-p302 :021 > Array nil | |
| # => [] | |
| # ruby-1.8.7-p302 :022 > Array false | |
| # => [false] | |
| # ruby-1.8.7-p302 :023 > Array true | |
| # => [true] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment