Class: Mail::FieldList
- Includes:
- Enumerable
- Defined in:
- lib/mail/field_list.rb
Overview
Field List class provides an enhanced array that keeps a list of email fields in order. And allows you to insert new fields without having to worry about the order they will appear in.
Instance Method Summary collapse
-
#<<(new_field) ⇒ Object
Insert the field in sorted order.
Instance Method Details
#<<(new_field) ⇒ Object
Insert the field in sorted order.
Heavily based on bisect.insort from Python, which is:
Copyright (C) 2001-2013 Python Software Foundation.
Licensed under <http://docs.python.org/license.html>
From <http://hg.python.org/cpython/file/2.7/Lib/bisect.py>
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mail/field_list.rb', line 17 def <<( new_field ) lo = 0 hi = size while lo < hi mid = (lo + hi) / 2 if new_field < self[mid] hi = mid else lo = mid + 1 end end insert(lo, new_field) end |