From: Brian Candler Date: 2011-12-05T22:27:43+09:00 Subject: Re: Stupid question Admin Tensor wrote in post #1034521: >> irb(main):002:0> s="9"*1149;s.sum%(48*s.size) >> => 10341 >> >> For longer strings, pass an argument to String#sum bigger than the >> default 16. >> > Very good, Aaron. Now, is there any way to replace that "s.size" with > something to make it really a one-liner (without the semicolon): > "some number".sum%(48 times something) > ? lambda {|x| x.sum%(48*x.size)}["9"*1149] Or something nasty with "->" if under ruby 1.9. But once you go to that extreme, you might as well stick with the more obvious and complete: ("9"*1149).chars.inject(0){|a,b|a+b.to_i} -- Posted via http://www.ruby-forum.com/.