/ Published in: Ruby
Expand |
Embed | Plain Text
class Array # order the elements of this array by the values of the specified attribute of # each element # def sort_by_attribute! atb sort! {|a,b| a.send(atb) <=> b.send(atb)} end # provides the first element of this array for which the block provides "true" # def first_where each do |element| return element if yield element end nil end def index_of_first_where each_with_index do |element,i| return i if yield element end end end
You need to login to post a comment.
