Shodhan Sheth
22.m@Pune
single n lookin
shodhan[dot]sheth[at]gmail[dot]com

linkZ n feedZ

Site Feed(Atom)
Geeky Feed(RSS/Atom Combo)
BlogLines Subscription
del.icio.us feed(RSS)

Powered by
Blogger

Creative Commons License
This work is licensed under a Creative Commons License.

Tuesday, November 22, 2005

GroovY vs RubY {Closures} - II

Surprisingly while tryin to implement a simple closure example in ruby i overlooked a kouple of immensely helpful methods. with the excitement kooled down now, i present a simpler variant of the same.
class Array

def apply
collect! { |number| yield number }
end

end
a=[1,2,3]
a.apply { |i| i * i }
p a.to_s


Tags : , ,

0 Comments:

Post a Comment

<< Home

Get awesome blog templates like this one from BlogSkins.com