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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/robust_excel_ole/general.rb', line 47 def / path_part if empty? path_part else if path_part.nil? || 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/robust_excel_ole/general.rb', line 75 def constantize names = 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
64 65 66 67 68 69 70 71 |
# File 'lib/robust_excel_ole/general.rb', line 64 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 |