Sha256: d04ebad046e5fc44814b21f7c4c350d00ab6058ed8e052194b10fd88cc6126a5
Contents?: true
Size: 624 Bytes
Versions: 1
Compression:
Stored size: 624 Bytes
Contents
# frozen_string_literal: true module Runger 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
runger_config-4.0.0 | lib/runger/ext/string_constantize.rb |