From: tamouse mailing lists Date: 2013-02-25T00:59:51+09:00 Subject: Re: How should I print only the last combination when using Array#combination(n) ? On Sun, Feb 24, 2013 at 9:40 AM, Love U Ruby wrote: > tamouse mailing lists wrote in post #1098790: >> On Sun, Feb 24, 2013 at 9:15 AM, Love U Ruby >> wrote: >>>>> >>> >>> -- >>> Posted via http://www.ruby-forum.com/. >>> >> >> I have no idea what you're saying there. >> >> Other than get the last combination, what is it you actually want to >> do? What is the application? > > Okay! I want to write a one liner which can give me the below output: I don't see any example output here... > which is currently I am not able by the below block code with > combination,as in the below block I couldn't track the,say,when second > 'arr' is coming just print it,but not the others.: > >>> a.combination(2){|arr| print arr.length;print "~~>";print arr ; print "=>" ; p > arr} > 2~~>[1, 2]=>[1, 2] > 2~~>[1, 3]=>[1, 3] > 2~~>[2, 3]=>[2, 3] > => [1, 2, 3] > > Please let me know if still my need confuses you. Still don't know what your need is... If I guessed, is it this? 1.9.3-head :007 > [1,2,3].combination(2).to_a.last.tap{|t| puts "#{t.length}~~>#{t}=>#{t}" } 2~~>[2, 3]=>[2, 3] ? Can you describe what you're trying to do from the beginning before you decided to go down the combination route? > -- > Posted via http://www.ruby-forum.com/. >