4 ms·
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.
by matthewmacleod 13y ago
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.
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/ https://github.com/rubyspec/rubyspec/ and specifically case statement spec at https://github.com/rubyspec/rubyspec/blob/master/language/case_spec.rb https://github.com/rubyspec/rubyspec/blob/master/language/ca...
- masklinn 13y ago> Ruby's case statements are super-awesome 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-expressions http://learnyouahaskell.com/syntax-in-functions#case-express... [2] http://learnyousomeerlang.com/syntax-in-functions#in-case-of http://learnyousomeerlang.com/syntax-in-functions#in-case-of [3] http://en.wikibooks.org/wiki/F_Sharp_Programming/Pattern_Matching_Basics http://en.wikibooks.org/wiki/F_Sharp_Programming/Pattern_Mat...