Add h
-
Tell me how to form a similar hech. I have a type cycle:
sms_send = {} SmsSend.all.each do |record| if !record.is_send sms_send.merge!(record.sms_number => Russian.translit(record.sms_text)) record.is_send = 1 record.save end
On the way out, it looks like:
{'12345678' => 'test1', '123456789' => 'test1'}
♪ How to make it even more important,record.uid
so that there's a hush on the way out:{ 'record.uid(1)' => { record.sms_number(1) => Russian.translit(record.sms_text(1)) }, 'record.uid(2)' => { record.sms_number(2) => Russian.translit(record.sms_text(2)) } }
i.e. to have a unique key first.
record.uid
And then you went for it? To add values on each iteration, depending on the conditions.
-
If
uid
Unique, such a design can be used:sms_end = {} SmsSend.find_each.with_object(sms_end) do |record, memo| next if record.is_send memo[record.uid] = {record.sms_number => Russian.translit(record.sms_text)} end
Output retained
sms_end
♪As commented, this is the best option.