Skip to content

Instantly share code, notes, and snippets.

@claudiug
Forked from jrochkind/slug.rb
Created May 23, 2020 22:15
Show Gist options
  • Save claudiug/97c72a03f0ab1010285f9ad5d4bb6b76 to your computer and use it in GitHub Desktop.
Save claudiug/97c72a03f0ab1010285f9ad5d4bb6b76 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