Module: Bumbleworks::Support
- Defined in:
- lib/bumbleworks/support.rb
Overview
Support methods for utility functionality such as string modification - could also be accomplished by monkey-patching String class.
Class Method Summary collapse
Class Method Details
.all_files(directory, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/bumbleworks/support.rb', line 12 def all_files(directory, = {}) Dir["#{directory}/**/*.rb"].inject({}) do |memo, path| name = File.basename(path, '.rb') name = camelize(name) if [:camelize] == true memo[path] = name memo end end |
.camelize(string) ⇒ Object
7 8 9 10 |
# File 'lib/bumbleworks/support.rb', line 7 def camelize(string) string = string.sub(/^[a-z\d]*/) { $&.capitalize } string = string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') end |
.constantize(name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bumbleworks/support.rb', line 21 def constantize(name) name_parts = name.split('::') name_parts.shift if name_parts.first.empty? constant = Object name_parts.each do |name_part| constant_defined = if Module.method(:const_defined?).arity == 1 constant.const_defined?(name_part) else constant.const_defined?(name_part, false) end constant = constant_defined ? constant.const_get(name_part) : constant.const_missing(name_part) end constant end |