On Wednesday, June 25, 2014 4:44:27 PM UTC-5, mpou...@afilias.info wrote: > > > While migrating our local modules from puppet 2 to puppet 3 I think I've > found a backwards-incompatible change that's not listed in the release > notes. I'd like to verify that what I'm seeing is expected, and make sure > I'm not missing any other side-effects of the change. > > In puppet 2 templates, array slices which returned a single element were > still returned as an array, so a structure like this was valid: > > <%- myarray[-1].each do |text| -%> > <%=text%> > <%- end -%> > > In puppet 3 templates this throws an error: > undefined method `each' for "foo":String at ... > > It looks like slices that return only a single element are now returned as > the type of the array element rather than as an array. I don't see this > change mentioned anywhere at < > http://docs.puppetlabs.com/puppet/3/reference/release_notes.html>. > > Is there anything else to this change that I'm missing, or are there other > side-effects to this I should be watching out for? > >
Yes. 1. The meaning of Ruby scriptlet code in an ERB template is determined by Ruby, not by Puppet. If there had been a change, then there would be no particular reason to expect it to be called out in Puppet's release notes. 2. The Ruby expression myarray[-1] does not compute an array slice, it returns the last element of the array. As far as I am aware, it hasn't computed a slice in any version of Ruby. The behavior you describe is normal, and does not itself reflect a change in Puppet *or* Ruby. Presumably the real code that caused you trouble has something more subtle going on. For example, maybe the structure of myarray ends up being different in Puppet 3 than in Puppet 2. I would need to see the real manifests by which its value is assigned to guess at why. 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 puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/bc92d316-150b-4dd5-a2f7-5b6ce7b27f3e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.