From: Daniel Schierbeck Date: 2006-08-08T00:05:07+09:00 Subject: Re: nextPowerOf2(n) Ch Skilbeck wrote: > def nextPowerOf2(n) > raise "integer please" if !n.kind_of? Integer > high = 0 > count = 0 > (0..n.size * 8 - 2).each {|b| count += n[b] ; high = b if n[b] != 0} > 1 << high + (count > 1 ? 1 : 0) > end Your question has already been answered by Simon, but I'd like to show you how your code could be more Rubyesque. First off, method name are always lower_case_with_underscore, so def next_power_of_2(n) Ruby has the `unless' keyword, so raise "integer please" unless n.kind_of? Integer but you don't really have to check the argument's class -- just check if the provided object responds to #to_int, or don't even check at all. raise "integer please" unless n.respond_to? :to_int n = n.to_int Parallel assignment is cool high, count = 0, 0 I'd split the next part up, but that may just be me (0..(n.size * 8 - 2)).each do |b| count += n[b] high = b unless n[b] == 0 end Just some thoughts Cheers, Daniel