Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

elliott cable http://elliottcable.name/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

file extension methods

Allows you to use file extensions as methods

   1  
   2  class File
   3    # Feel free to add more here, as you need them.
   4    Extensions = %r=^(txt|rb|markdown|textile|haml|sass|css|html|xhtml)$=i
   5    
   6    module Extension
   7      def method_missing(meth, *args)
   8        if Extensions =~ meth.to_s
   9          [self, '.', meth.to_s].join
  10        else
  11          super
  12        end # if
  13      end # method_missing
  14    end # Extension
  15  end # File
  16  
  17  class Symbol
  18    include File::Extension
  19  end
  20  class String
  21    include File::Extension
  22  end


   1  
   2  'myfile'.html
   3  # => "myfile.html"
   4  
   5  :a_file.rb
   6  # => "a_file.rb"
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS