Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
Method extraction refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilger committed Sep 14, 2014
1 parent bf2e4d6 commit 0263073
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/kookaburra/dependency_accessor.rb
Expand Up @@ -12,13 +12,20 @@ def dependency_accessor(*names)
private

def define_dependency_accessor(name)
define_attr_reader(name)
define_attr_writer(name)
end

def define_attr_reader(name)
define_method(name) do
class_name = self.class.name
class_name.sub!(/^$/, 'an Anonymous Class!!!')
instance_variable_get("@#{name}") or raise "No %s object was set on %s initialization." \
% [name, class_name]
end
end

def define_attr_writer(name)
define_method("#{name}=") do |value|
instance_variable_set("@#{name}", value)
end
Expand Down

0 comments on commit 0263073

Please sign in to comment.