Alex Gutteridge
9/7/2007 2:25:00 AM
On 7 Sep 2007, at 10:55, Lloyd Linklater wrote:
> Jeremy Woertink wrote:
>> end.delete_at(-1)
>
> OMG! You can call methods in an end??? I have lived far to long
> in the
> scalar world! When would you do such a thing?
Remember do..end is just another way of saying {..}
If I need to filter things out of an array of data I often do things
like:
data = [1,2,3,4,5,6,6,7,7]
data.find_all{|x| x > 5}.uniq
=> [6, 7]
Thats just the same as:
data.find_all do |x|
x > 5
end.uniq
=> [6, 7]
I do tend to use the {..} syntax if I'm chaining calls like this
though because 'calling' methods on end looks weird to me as well.
Alex Gutteridge
Bioinformatics Center
Kyoto University