module Pallets::Util
Public Instance Methods
constantize(str)
click to toggle source
# File lib/pallets/util.rb, line 11 def constantize(str) names = str.split('::') # Raise the "usual" NameError Object.const_get(str) if names.empty? # Handle "::Const" cases names.shift if names.first.empty? names.inject(Object) do |constant, name| if constant.const_defined?(name, false) constant.const_get(name, false) else constant.const_missing(name) end end end
generate_id(str)
click to toggle source
# File lib/pallets/util.rb, line 5 def generate_id(str) initials = str.gsub(/[^A-Z]+([A-Z])/, '\1')[0,3] random = SecureRandom.hex(5) "#{initials}#{random}" end