# Ruby Pattern Matching

**URL:** <https://forum.elixirforum.com/t/ruby-pattern-matching/25689>\
**Category:** General Prog (Archived)\
**Tags:** ruby\
**Created:** [September 26, 2019, 8:12pm UTC](https://forum.elixirforum.com/t/ruby-pattern-matching/25689 "2019-09-26T20:12:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![khedaywi](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/khedaywi/32/6718_2.png) [@khedaywi](https://forum.elixirforum.com/u/khedaywi)\
**Post date:** [September 26, 2019, 8:12pm UTC](https://forum.elixirforum.com/t/ruby-pattern-matching/25689/1 "2019-09-26T20:12:48Z")

</div>

For those of you using Ruby and miss pattern matching in Elixir, it looks like Ruby is adding some pattern matching functionality to Ruby 2.7 via case statements. Not exactly the same, but seems nice nonetheless!

Here’s an overview: [https://medium.com/cedarcode/ruby-pattern-matching-1e84cab3b44a](https://medium.com/cedarcode/ruby-pattern-matching-1e84cab3b44a)

```elixir
case 0
in 0
  :match
end
#=> :match
case 0
in -1..1
  :match
end
#=> :match
case 0
in 3..6
  :no_match
end
#=> NoMatchingPatternError (0)
case 0
in Integer
  :match
end
#=> :match
case 0
in String
  :no_match
end
#=> NoMatchingPatternError (0)

case [0, 1, 2]
in [0, a, 3]
 :no_match       
end
#=> NoMatchingPatternError ([0, 1, 2])
case [0, 1, 2]
in [0, a, 2]
 a        
end
#=> 1
case [0, 1, 2]
in [0, *tail]
 tail  
end
#=> [1, 2]

```
