Skip to content

Instantly share code, notes, and snippets.

@jrochkind
Last active September 23, 2022 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jrochkind/c45dffb80b600fdaa177f10873889d3b to your computer and use it in GitHub Desktop.
Save jrochkind/c45dffb80b600fdaa177f10873889d3b to your computer and use it in GitHub Desktop.
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