The capability was already there via to_hash, and
Enumerable was already included, but this method was
missing.  Given the kind of hacking RI is doing,
this seemed appropriate.

Signed-off-by: Luke Kanies <[email protected]>
---
Local-branch: refactor/master/8232-array_indexers_on_scope
 lib/puppet/parser/scope.rb     |    4 ++++
 spec/unit/parser/scope_spec.rb |   12 ++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 7b75ca8..3a87f96 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -82,6 +82,10 @@ class Puppet::Parser::Scope
     compiler.catalog
   end
 
+  def each
+    to_hash.each { |name, value| yield(name, value) }
+  end
+
   # Proxy accessors
   def host
     @compiler.node.name
diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb
index 887890e..78feaf0 100755
--- a/spec/unit/parser/scope_spec.rb
+++ b/spec/unit/parser/scope_spec.rb
@@ -122,6 +122,18 @@ describe Puppet::Parser::Scope do
       @scope.should_not be_include("var")
     end
 
+    it "should support iteration over its variables" do
+      @scope["one"] = "two"
+      @scope["three"] = "four"
+      hash = {}
+      @scope.each { |name, value| hash[name] = value }
+      hash.should == {"one" => "two", "three" => "four" }
+    end
+
+    it "should include Enumerable" do
+      @scope.singleton_class.ancestors.should be_include(Enumerable)
+    end
+
     describe "and the variable is qualified" do
       before do
         @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foonode"))
-- 
1.7.3.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to