Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/robust_excel_ole/general.rb
Overview
:nodoc: #
Instance Method Summary collapse
- #/(path_part) ⇒ Object
-
#constantize ⇒ Object
taken from apidock.com/rails/ActiveSupport/Inflector/constantize File activesupport/lib/active_support/inflector/methods.rb, line 226.
- #underscore ⇒ Object
Instance Method Details
#/(path_part) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/robust_excel_ole/general.rb', line 35 def / path_part if empty? path_part else if path_part.nil? or path_part.empty? self else begin File.join self, path_part rescue TypeError raise TypeError, "Only strings can be parts of paths (given: #{path_part.inspect} of class #{path_part.class})" end end end end |
#constantize ⇒ Object
taken from apidock.com/rails/ActiveSupport/Inflector/constantize File activesupport/lib/active_support/inflector/methods.rb, line 226
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/robust_excel_ole/general.rb', line 63 def constantize names = self.split('::') # Trigger a builtin NameError exception including the ill-formed constant in the message. Object.const_get(self) 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| if constant == Object constant.const_get(name) else candidate = constant.const_get(name) next candidate if constant.const_defined?(name) next candidate unless Object.const_defined?(name) # Go down the ancestors to check it it's owned # directly before we reach Object or the end of ancestors. constant = constant.ancestors.inject do |const, ancestor| break const if ancestor == Object break ancestor if ancestor.const_defined?(name) const end # owner is in Object, so raise constant.const_get(name) end end end |
#underscore ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/robust_excel_ole/general.rb', line 52 def underscore word = gsub('::', '/') word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end |