I would use do ... end
blocks for multi-line and curly braces { ... }
for one-line code. I never use do ... end
for chaining methods, except when preceding for a multi-line block. I also chain methods in the same line as longer as the code is readable and the line is no longer than 80 chars.
So your example I will code it as below:
def example1 (arr)
arr.sort do |a, b|
a_pieces = a.value.split ' '
b_pieces = b.value.split ' '
(a_pieces[1] + a_pieces[5]) <=> (b_pieces[1] + b_pieces[5])
end.last[:some_value].select { |a| a == 'something' }
end
Although I probably will split it in two methods (actually three with the example1 one):
def sort_array(arr)
arr.sort do |a, b|
a_pieces = a.value.split ' '
b_pieces = b.value.split ' '
(a_pieces[1] + a_pieces[5]) <=> (b_pieces[1] + b_pieces[5])
end
end
def select_item(arr)
arr.last[:some_value].select { |a| a == 'something' }
end
def example1(arr)
select_item(sort_array(arr))
end