<commit_before>---
published: true
title: swith/case statement
tags: ruby
---
> `case x` - [Advanced techniques](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/)
- `when String` - [matching object class](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#matching-ranges-in-case-statements)  
- `when (1..10)` -  [matching ranges](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#matching-ranges-in-case-statements)
- `when /BAR$/` - [matching regular expressions](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#matching-regular-expressions-with-case-statements)
- `when -> (n) { n.to_s == "40" }` - [Matching procs and lambdas](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#matching-procs-and-lambdas)
- `when Success` - [Writing your own matcher classes](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#writing-your-own-matcher-classes)

simple as defining your own === method
{% highlight  ruby %}
class Success
  def self.===(item)
    item.status >= 200 && item.status < 300<commit_msg>Update 2019-11-20-ruby-case-when.md<commit_after>---
published: true
title: swith/case statement
tags: ruby
---
> `case x` - [Advanced techniques](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/)

- `when String` - [matching object class](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#matching-ranges-in-case-statements)  
- `when (1..10)` -  [matching ranges](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#matching-ranges-in-case-statements)
- `when /BAR$/` - [matching regular expressions](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#matching-regular-expressions-with-case-statements)
- `when -> (n) { n.to_s == "40" }` - [Matching procs and lambdas](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#matching-procs-and-lambdas)
- `when Success` - [Writing your own matcher classes](https://www.honeybadger.io/blog/rubys-case-statement-advanced-techniques/#writing-your-own-matcher-classes)

simple as defining your own === method
{% highlight  ruby %}
class Success
  def self.===(item)
    item.status >= 200 && item.status < 300
{'fraction_non_alphanumeric': 0.1719222462203024, 'fraction_numerical': 0.012958963282937365, 'mean_word_length': 4.580722891566265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 12, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1668447', 'n_tokens_mistral': 834, 'n_tokens_neox': 760, 'n_words': 114}