Class: String
Instance Method Summary collapse
- #classify ⇒ Object
- #satisfies_requirement?(requirement_string) ⇒ Boolean
-
#underscore ⇒ Object
:reek:TooManyStatements.
- #which ⇒ Object
Instance Method Details
#classify ⇒ Object
38 39 40 41 42 |
# File 'lib/core_ext.rb', line 38 def classify sub(/^[a-z\d]*/, &:capitalize).gsub(%r{(?:_|(\/))([a-z\d]*)}i) do "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" end.gsub('/', '::') end |
#satisfies_requirement?(requirement_string) ⇒ Boolean
44 45 46 47 48 |
# File 'lib/core_ext.rb', line 44 def satisfies_requirement?(requirement_string) version = Gem::Version.new(self) requirement = Gem::Requirement.new(requirement_string) requirement.satisfied_by?(version) end |
#underscore ⇒ Object
:reek:TooManyStatements
30 31 32 33 34 35 36 |
# File 'lib/core_ext.rb', line 30 def underscore return self unless self =~ /[A-Z-]|::/ word = to_s.gsub('::', '/') word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr('-', '_').downcase end |
#which ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/core_ext.rb', line 21 def which bin_path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |path| file = File.join(path, self) File.exist?(file) && File.executable?(file) end bin_path ? File.join(bin_path, self) : nil end |