On Monday, October 6, 2014 1:47:31 PM UTC-5, Ciro Iriarte wrote:
 

> Trying this approach I get "Detail: undefined method `each_pair' for 
> #<Array:0x7f19bc81d288>" using this code:
>
>
> <% if (@ospfconfig.is_a?(Hash)) and (@ospfconfig.count > 0) -%>
> <% @ospfconfig.sort.each do |instance,instparam| -%>
> protocol ospf <%= instance %> {
>
> }
> <% end -%>
> <% end -%>
>
>

Well, you didn't get such an error with *that* code, as it doesn't use 
each_pair.  You can use Hash.each(), but in that case, instead of getting 
the key and value directly, each item iterated is an array of form [ key, 
value ].  So you might use this variation:

<%
  @ospf.sort.each do |pair|
    instance = pair[0]
    instance_data = pair[1]
-%>

 

> Can it be a Ruby version thing?
>
>

Yes.  Hash.each_pair() is new in Ruby 1.9.

Hash.each() exists in 1.8.  I prefer it to Hash.each_slice() for this 
purpose, though the two would work similarly, because the meaning and 
behavior of the Hash.each() are clearer to me.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/d4c49a4b-5e46-4f8b-8616-43ad2ca6a164%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to