diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-03-26 17:56:16 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-03-26 17:56:44 -0700 |
commit | bca7770e6c05ca2d81302349b02b058ade00d491 (patch) | |
tree | 6b331b5013e29210f84004a48ddf1a56f73b30d5 /railties/lib/rails | |
parent | 37c84ed877188151c14af2b1401e4f2bd860bdd7 (diff) | |
download | rails-bca7770e6c05ca2d81302349b02b058ade00d491.tar.gz rails-bca7770e6c05ca2d81302349b02b058ade00d491.tar.bz2 rails-bca7770e6c05ca2d81302349b02b058ade00d491.zip |
favor composition over inheritance
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/paths.rb | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 82c40ebe4b..9730ed16e9 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -43,25 +43,40 @@ module Rails # root["app/controllers"].existent # => ["/rails/app/controllers"] # # Check the <tt>Rails::Paths::Path</tt> documentation for more information. - class Root < ::Hash + class Root attr_accessor :path def initialize(path) raise "Argument should be a String of the physical root path" if path.is_a?(Array) @current = nil @path = path - @root = self - super() + @root = {} end def []=(path, value) value = Path.new(self, path, [value].flatten) unless value.is_a?(Path) - super(path, value) + @root[path] = value end def add(path, options={}) with = options[:with] || path - self[path] = Path.new(self, path, [with].flatten, options) + @root[path] = Path.new(self, path, [with].flatten, options) + end + + def [](path) + @root[path] + end + + def values + @root.values + end + + def keys + @root.keys + end + + def values_at(*list) + @root.values_at(*list) end def all_paths |