T
trans. (T. Onoma)
I have this method:
def each_unique_pair
self.each_with_index{ |a,i|
self[(i+1)..-1].each{ |b| yield a,b }
}
end
I'm trying to write a generalized version but having a bit of time about it:
def each_unique(n=2)
# how?
end
My (imperfect) solutions keep leading me to recursion but I'd rather avoid it
(as I think it would be less efficient, correct me if I'm wrong)
Thanks,
T.
P.S. Does anyone have a really good String#word_wrap method? I wrote one but
it isn't so good b/c it strip newlines.
def each_unique_pair
self.each_with_index{ |a,i|
self[(i+1)..-1].each{ |b| yield a,b }
}
end
I'm trying to write a generalized version but having a bit of time about it:
def each_unique(n=2)
# how?
end
My (imperfect) solutions keep leading me to recursion but I'd rather avoid it
(as I think it would be less efficient, correct me if I'm wrong)
Thanks,
T.
P.S. Does anyone have a really good String#word_wrap method? I wrote one but
it isn't so good b/c it strip newlines.