Skip to content

Commit

Permalink
Simplify push! and pop! (since they don't have to be deep any more)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Nov 11, 2011
1 parent 4020c35 commit 0162212
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/confstruct/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ def configure *args, &block
end

def push! *args, &block
(self[:@stash] ||= []).push(self.deep_copy)
_stash.push(self.deep_copy)
configure *args, &block if args.length > 0 or block_given?
self
end

def pop!
s = self[:@stash]
if s.nil? or s.empty?
if _stash.empty?
raise IndexError, "Stash is empty"
else
obj = s.pop
obj = _stash.pop
self.clear
self[:@stash] = s unless s.empty?
self.merge! obj
after_config! self
end
Expand All @@ -46,6 +44,10 @@ def pop!
def reset_defaults!
self.replace(default_values.deep_copy)
end


protected
def _stash
@stash ||= []
end
end
end

0 comments on commit 0162212

Please sign in to comment.