method
Ruby
code posted
by
Gray
created at 18 Jul 20:59
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
def self.insert_samples str re = /(?<=\[@)(\d+)(?=\])/ samples = Hash.new self.find(str.scan(re).map { |a| a.join }).map do |obj| samples[obj.id.to_s] = obj end while num = str[re] str.sub!("[@#{num}]", samples[num].script) end str rescue ActiveRecord::RecordNotFound => e Rails.logger.error e.to_s return nil end |
358 Bytes in 2 ms with coderay