Skip to content

Instantly share code, notes, and snippets.

@rondy rondy/modularize.rb

Created Oct 26, 2011
Embed
What would you like to do?
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
You can’t perform that action at this time.