Sha256: 29daaf915cd8d73e4a999de4726ea94c5bffd1516d791c0ad45dacc92d80bae2

Contents?: true

Size: 806 Bytes

Versions: 5

Compression:

Stored size: 806 Bytes

Contents

module Scrooge
  module Core
    module String
      
      # Framework agnostic String <=> Constant helpers.
      # Perhaps not the cleanest abstraction, but also not good practice to piggy
      # back on or use a naming convention that may clash with and uproot the API
      # any given framework ships with.
      
      def to_const
        self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
      end
      
      def to_const!( instantiate = true )
        begin
          const = Object.module_eval(to_const, __FILE__, __LINE__)
          instantiate ? const.new : const
        rescue => exception 
          exception.to_s.match( /uninitialized constant/ ) ? self : raise
        end
      end
         
    end
  end
end

class String
  include Scrooge::Core::String
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
methodmissing-scrooge-1.0.0 lib/scrooge/core/string.rb
methodmissing-scrooge-1.0.1 lib/scrooge/core/string.rb
methodmissing-scrooge-1.0.2 lib/scrooge/core/string.rb
methodmissing-scrooge-1.0.3 lib/scrooge/core/string.rb
methodmissing-scrooge-1.0.4 lib/scrooge/core/string.rb