Last active
          February 21, 2025 17:41 
        
      - 
      
- 
        Save jrochkind/c45dffb80b600fdaa177f10873889d3b to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | module Slug | |
| def self.customize(field: :name) | |
| Module.new do | |
| define_method :to_param do | |
| public_send(field).downcase.gsub /\W+/, '-' | |
| end | |
| end | |
| end | |
| end | |
| class Cat | |
| include Slug.customize(field: 'hello') | |
| end | |
| # you can go further if you want... | |
| module Slug | |
| def self.customize(field: :name) | |
| Module.new do | |
| include Slug | |
| define_method :to_param do | |
| public_send(field).downcase.gsub /\W+/, '-' | |
| end | |
| end | |
| end | |
| def non_customized_method | |
| "everyone gets this" | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment