Sha256: 283845b353035eacf831b2bd70a2c1d2ca727a9532af7d1ba40210b70ac473dd
Contents?: true
Size: 856 Bytes
Versions: 26
Compression:
Stored size: 856 Bytes
Contents
module Cucumber module Constantize #:nodoc: def constantize(camel_cased_word) try = 0 begin try += 1 names = camel_cased_word.split('::') names.shift if names.empty? || names.first.empty? constant = ::Object names.each do |name| constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) end constant rescue NameError => e require underscore(camel_cased_word) if try < 2 retry else raise e end end end # Snagged from active_support def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end end end
Version data entries
26 entries across 24 versions & 8 rubygems