Created
November 21, 2012 14:43
-
-
Save ugisozols/4125166 to your computer and use it in GitHub Desktop.
Stop subclassing array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/lib/refinery/plugins.rb b/core/lib/refinery/plugins.rb | |
index a22497f..1d8e4ee 100644 | |
--- a/core/lib/refinery/plugins.rb | |
+++ b/core/lib/refinery/plugins.rb | |
@@ -1,5 +1,10 @@ | |
module Refinery | |
- class Plugins < Array | |
+ class Plugins | |
+ include Enumerable | |
+ | |
+ def initialize(*args) | |
+ @plugins = Array.new(*args) | |
+ end | |
def find_by_model(model) | |
model = model.constantize if model.is_a? String | |
@@ -31,6 +36,18 @@ module Refinery | |
map(&:title) | |
end | |
+ def <<(other) | |
+ plugins << other | |
+ end | |
+ | |
+ def each(*args, &block) | |
+ plugins.each(*args, &block) | |
+ end | |
+ | |
+ def delete_if(*args, &block) | |
+ plugins.delete_if(*args, &block) | |
+ end | |
+ | |
class << self | |
def active | |
@active_plugins ||= new | |
@@ -61,5 +78,8 @@ module Refinery | |
end | |
end | |
+ private | |
+ | |
+ attr_reader :plugins | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this work: