Browse files

Enable Ruby core extensions and String#camelcase.

Extensions to the Ruby core classes live in the rake/core_ext directory
and are enabled by updating rake/core_extensions.rb to require them.
The actual extension consists of two parts, both in the rake/core_ext

Part One is a file named after the Ruby core class that you intend to
extend, for example rake/core_ext/string.rb. It's responsibility is to
require all files implementing extensions to a particular core Ruby

Part Two is a subdirectory named after the Ruby core class you're extending.
For example, rake/core_ext/string/. This subdirectory holds all the files
that actually extend the core class named by the subdirectory. Use multiple
files to liberally modularize your extension code.

Finally, bringing everything together for use by the project rakefile, the
rake/core_extensions.rb file requires all Ruby core extensions you've
provided in Part One and Two.

Confusing? Don't let the above wording slow you down one bit. Check out the
code for the String#camelcase extension as managed by the following files:

 * rakefile.rb
 * rake/core_extensions.rb
 * rake/core_ext/string.rb
 * rake/core_ext/string/conversions.rb
  • Loading branch information...
1 parent bec1be0 commit 282e918881ad83fb1417132ed7a63ee97841c7a6 @jonforums jonforums committed Jul 28, 2010
Showing with 14 additions and 0 deletions.
  1. +1 −0 rake/core_ext/string.rb
  2. +9 −0 rake/core_ext/string/conversions.rb
  3. +1 −0 rake/core_extensions.rb
  4. +3 −0 rakefile.rb
@@ -0,0 +1 @@
+require 'rake/core_ext/string/conversions'
@@ -0,0 +1,9 @@
+class String
+ # Converts a lower case and underscored string to UpperCamelCase.
+ #
+ # Examples:
+ # "ruby_build_path".camelcase # => "RubyBuildPath"
+ def camelcase
+ self.gsub(/(?:\A|_)(.)/) { $1.upcase }
+ end
@@ -0,0 +1 @@
+require 'rake/core_ext/string'
@@ -8,6 +8,9 @@
require 'rake'
+# Add extensions to core Ruby classes
+require 'rake/core_extensions'
# Added download task from buildr
require 'rake/downloadtask'
require 'rake/extracttask'

0 comments on commit 282e918

Please sign in to comment.