That's exactly why it would be the most voted question. It's a common thing to Google, and the Google search leads to the StackOverflow page linked, which leads to lots of upvotes.
Yes, but if I want informations about Ruby switch statements it means you are a newbie that should refer to a whole language syntax reference; you could say that Ruby has not an official language syntax reference (this is the most "official": http://web.njit.edu/all_topics/Prog_Lang_Docs/html/ruby/synt... ) so newbies are forced to google for syntax explanations, which is true, but it seems too little to make it the first Ruby question.
And I think Ruby management has its negligence; it's weird that a so popular and mature language has so much lack of informations about its behaviour.
That question was...unexpected to me, to say the least. I was expecting something obscure, maybe related to meta programming, certainly not something about flow structures!
The ruby community does not really believe in documentation, so you have to go for third-party sources[0] or books
Also, it's not a simple control structure, Ruby's case/when does not do equality checks (via ==) it does match checks (via ===) so you can match integers to ranges:
The lack of documentation, especially when you want to do something non-standard, made me give up on RoR a few years ago. I got sick of getting lost when looking at the source, which seemed to consist of 5-10 line methods with a call hierarchy that was usually over 10 methods deep.
But "I don't believe in ..." or "She doesn't believe in ..." is a running gag in my circle of friends.
"He got rather bad teeth so he had to pay much money for getting them done..." - "Didn't his insurance cover this?" - "He doesn't believe in insurance!"
Ruby's case statements are super-awesome, and I constantly find myself longing for similar sugar elsewhere. Obviously it's more useful in a duck-typed language.
Most functional languages have, I think, somewhat better systems in that there's less magic[0], you can unwrap/extract values and you can add further conditions on values (guards)[1][2][3].
Some modern multiparadigm languages have lifted this style e.g. Scala or Rust.
[0] because case/when relies on the non-commutative `===` its behavior can be surprising
21 comments
[ 2.7 ms ] story [ 60.3 ms ] threadAnd I think Ruby management has its negligence; it's weird that a so popular and mature language has so much lack of informations about its behaviour.
Java: http://stackoverflow.com/questions/11227809/why-is-processin...
Php: http://stackoverflow.com/questions/60174/how-can-i-prevent-s...
Javascript: http://stackoverflow.com/questions/111102/how-do-javascript-...
Ruby, Python, Javascript: unique-ish language features
Java: general comp-sci corner cases
C, C++: what does this obscure operator mean
Erlang, Haskell, Node: how to get started
Go: how to live without features that were intentionally not included
PHP: How to avoid the security pitfalls that the standard library encourages
Seems about right... (Though I'm surprised to see Node alongside Erlang and Haskell in terms of people not knowing where to start)
Also, it's not a simple control structure, Ruby's case/when does not do equality checks (via ==) it does match checks (via ===) so you can match integers to ranges:
or instances to classes But `===` is not commutative: and the matches can seem somewhat arbitrary: [0] http://www.techotopia.com/index.php/The_Ruby_case_Statementmade my day, thanks.
But "I don't believe in ..." or "She doesn't believe in ..." is a running gag in my circle of friends.
"He got rather bad teeth so he had to pay much money for getting them done..." - "Didn't his insurance cover this?" - "He doesn't believe in insurance!"
RubySpec, for those who aren't familiar with it, is an attempt to write an executable specification for the language. Ruby's definitely suffered from not having this in the past. https://github.com/rubyspec/rubyspec/ and specifically case statement spec at https://github.com/rubyspec/rubyspec/blob/master/language/ca...
Most functional languages have, I think, somewhat better systems in that there's less magic[0], you can unwrap/extract values and you can add further conditions on values (guards)[1][2][3].
Some modern multiparadigm languages have lifted this style e.g. Scala or Rust.
[0] because case/when relies on the non-commutative `===` its behavior can be surprising
[1] http://learnyouahaskell.com/syntax-in-functions#case-express...
[2] http://learnyousomeerlang.com/syntax-in-functions#in-case-of
[3] http://en.wikibooks.org/wiki/F_Sharp_Programming/Pattern_Mat...