Sha256: 677bb94eaa9b7cb9fa53dafedc5a02e7021a689cf68322fa5c151b9f95af3c78
Contents?: true
Size: 630 Bytes
Versions: 33
Compression:
Stored size: 630 Bytes
Contents
# frozen_string_literal: true module ActionPolicy module Ext # Add simple safe_constantize method to String module StringConstantize refine String do def safe_constantize names = split("::") return nil if names.empty? # Remove the first blank element in case of '::ClassName' notation. names.shift if names.size > 1 && names.first.empty? names.inject(Object) do |constant, name| break if constant.nil? constant.const_get(name, false) if constant.const_defined?(name, false) end end end end end end
Version data entries
33 entries across 33 versions & 1 rubygems