Is there anyway to find the next item in a Ruby Array?
Code:
# Find ALL languages
if !debug
lang = Language.all
else
lang = Language.where("id = ? OR id = ?", 22, 32)
end
# Get all elements
elements = Element.where("human_readable IS NOT NULL")
lang.each do |l|
code = l.code.downcase
if File.exists?(file_path + code + ".yml")
File.delete(file_path + code + ".yml")
end
t1 = Time.now
info = {}
elements.each do |el|
unless l.id == 1
et = el.element_translations.where("language_id = ? AND complete = ?", l.id, true)
else
et = el.element_translations.where("language_id = ?", 1)
end
et.each do |tran|
info[code] ||= {}
info[code][el.human_readable] = tran.content.gsub("\n", "").force_encoding("UTF-8").encode!
end
end
File.open(file_path + code + ".yml", "w", :encoding => "UTF-8") do |f|
if f.write(info.to_yaml)
t2 = Time.now
puts code + ".yml File written"
puts "It took " + time_diff_milli(t1, t2).to_s + " seconds to complete"
# This is where I want to display the next item in the lang array
puts lang.shift(1).inspect
puts "*"*50
end
end
end
puts lang.shift(1).inspect, using that inside a block iterating over lang might cause some issues. Then again, it might not.x = array[i]andy = array[i+1]. This is not even programming 101, it's programming kindergarten, so we can't imagine this is what you are asking. This isn't meant to offend but to clarify.