Module: ArrayExtensions
- Included in:
- Array
- Defined in:
- lib/extensions/array_extensions.rb
Overview
Array extensions
Instance Method Summary collapse
- #last_index(item) ⇒ Object
- #rotate!(cnt = 1) ⇒ Object
- #to_downcase_str_arr ⇒ Object
- #to_f ⇒ Object
- #to_i_arr ⇒ Object
- #to_str_arr ⇒ Object
Instance Method Details
#last_index(item) ⇒ Object
21 22 23 |
# File 'lib/extensions/array_extensions.rb', line 21 def last_index(item) self.length - 1 - self.reverse.index(item) end |
#rotate!(cnt = 1) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/extensions/array_extensions.rb', line 25 def rotate!(cnt=1) cnt.times do tmp = self.shift self.push(tmp) end self end |
#to_downcase_str_arr ⇒ Object
13 14 15 |
# File 'lib/extensions/array_extensions.rb', line 13 def to_downcase_str_arr self.collect{|x| x.to_s.downcase} end |
#to_f ⇒ Object
4 5 6 7 |
# File 'lib/extensions/array_extensions.rb', line 4 def to_f epoch = DateTime.new(1970, 1, 1) (self - epoch).to_f * 24 * 60 * 60 # DateTime deltas are in days end |
#to_i_arr ⇒ Object
17 18 19 |
# File 'lib/extensions/array_extensions.rb', line 17 def to_i_arr self.collect{|x| x.to_i} end |
#to_str_arr ⇒ Object
9 10 11 |
# File 'lib/extensions/array_extensions.rb', line 9 def to_str_arr self.collect{|x| x.to_s} end |