Skip to content
Browse files

Add explanation for case

  • Loading branch information...
1 parent b13200c commit cf0b42b64e4470dc3dc627ce19e93211b64177b8 @radar radar committed Sep 20, 2010
Showing with 20 additions and 0 deletions.
  1. +8 −0 explanations/case.md
  2. +12 −0 fixtures/case.rb
View
8 explanations/case.md
@@ -0,0 +1,8 @@
+## `case` statement
+
+A `case` statement is used for when you want to act on a returned value that could be one of many different values. The value passed to the `case` statement is the value which is being checked. The `when` statements inside the case use a triple-equal (`===`) call to determine if the two objects are equal, using the value from the `when` as the left-hand side of the operation and the value from the `case` as the right-hand side.
+
+This triple-equal sign is how you may check to see if the specified object is of a specific type:
+
+ >> String === "a"
+ => true
View
12 fixtures/case.rb
@@ -0,0 +1,12 @@
+foo = "a"
+case foo
+ when "a"
+ puts "foo is a"
+ when "b"
+ puts "foo is b"
+end
+
+case foo
+ when String
+ puts "foo is string"
+end

0 comments on commit cf0b42b

Please sign in to comment.
Something went wrong with that request. Please try again.