Skip to content

Instantly share code, notes, and snippets.

@rmoriz
Created February 16, 2011 10:03
Show Gist options
  • Select an option

  • Save rmoriz/829122 to your computer and use it in GitHub Desktop.

Select an option

Save rmoriz/829122 to your computer and use it in GitHub Desktop.
# 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