Sha256: b5f77f62a6a49d9a7ddb5ec3ea934da899054289bf7554a6682d6ebc0c8b1335
Contents?: true
Size: 624 Bytes
Versions: 20
Compression:
Stored size: 624 Bytes
Contents
# frozen_string_literal: true module Anyway 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
20 entries across 20 versions & 2 rubygems