Skip to content

Instantly share code, notes, and snippets.

@benolee
Created October 28, 2011 19:24
Show Gist options
  • Save benolee/1323225 to your computer and use it in GitHub Desktop.
Save benolee/1323225 to your computer and use it in GitHub Desktop.
CamelCase guard name to find guard class name
diff --git a/lib/guard.rb b/lib/guard.rb
index 368d5aa..2795dc4 100644
--- a/lib/guard.rb
+++ b/lib/guard.rb
@@ -398,10 +398,10 @@ module Guard
def get_guard_class(name)
name = name.to_s
try_require = false
- const_name = name.downcase.gsub('-', '')
+ const_name = name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
begin
require "guard/#{ name.downcase }" if try_require
- self.const_get(self.constants.find { |c| c.to_s.downcase == const_name })
+ self.const_get(self.constants.find { |c| c.to_s == const_name })
rescue TypeError
unless try_require
try_require = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment