Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • It's commonly called the "space-ship operator". It's always a binary-comparison operator in Perl, which is where Ruby inherited it from. Commented Nov 27, 2013 at 16:51
  • Also, use snake_case, not camelCase for variables in Ruby. And, your examples don't work. Use first_element and second_element and make sure your assignments and variable spellings are consistent. It's a good idea to use IRB to test your examples, and then copy and paste them once they work. Commented Nov 27, 2013 at 16:58
  • "...an array of strings or complex objects then it doesnt know how to compare those objects"? Ruby knows how to compare strings just like it does single characters, which are strings. %w[foo bar].sort # => ["bar", "foo"]. Commented Nov 27, 2013 at 17:38