Skip to content

Instantly share code, notes, and snippets.

@rondy
Created October 26, 2011 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondy/1317425 to your computer and use it in GitHub Desktop.
Save rondy/1317425 to your computer and use it in GitHub Desktop.
require "active_support/inflector"
module Modularizable
def modularize(target, params={})
ancestors = params[:in] || []
ancestors << target
ancestors.collect { |item| item.to_s.camelize }.join("::").constantize
end
end
module UserPermissions
extend Modularizable
def self.factory(role)
modularize role, :in => [:user_permissions, :roles]
end
module Roles
module Admin;end
module Guest;end
end
end
puts UserPermissions.factory :admin # => UserPermissions::Roles::Admin
puts UserPermissions.factory :guest # => UserPermissions::Roles::Guest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment