Skip to content

Commit

Permalink
Implemented basic inheritance.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfue committed Feb 16, 2009
1 parent 569be26 commit 0e47332
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/shadows.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,9 @@
module Shadows module Shadows


def self.shadow_class(base) def self.shadow_class(base, fallback = nil)
"#{ base.name }Shadow".constantize "#{ base.name }Shadow".constantize
rescue NameError => e rescue NameError => e
Class.new Shadows::Base do fallback or Class.new Shadows::Base do
helper = "#{ base.name.pluralize }Helper".constantize rescue nil helper = "#{ base.name.pluralize }Helper".constantize rescue nil
include helper if helper include helper if helper
end end
Expand Down Expand Up @@ -43,6 +43,10 @@ def self.extended(base)
base.instance_variable_set :@shadow, Shadows.shadow_class(base) base.instance_variable_set :@shadow, Shadows.shadow_class(base)
end end
attr_reader :shadow attr_reader :shadow
def inherited(base)
super
base.instance_variable_set :@shadow, Shadows.shadow_class(base, @shadow)
end


end end
module InstanceMethods module InstanceMethods
Expand Down

0 comments on commit 0e47332

Please sign in to comment.