Hi --

On Sat, 25 Mar 2006, Robert Klemme wrote:

> Shea Martin wrote:
>> This works nicely, but I am sure something like this is already built in, 
>> but I can't seem to find it.
>> 
>> def require_version( p_ver_str )
>>   l_have = VERSION.split('.')
>>   l_need = p_ver_str.split('.')
>>   l_need.each_index do |i|
>>     if l_have[i].to_i < l_need[i].to_i
>>       raise ScriptError, "Required Ruby #{p_ver_str}, found Ruby 
>> #{VERSION}"
>>     end
>>   end
>> end
>
> Hmmm, lettsee whether we can compress that a bit. How about:
>
> def ensure_version(ver)
>  raise "Requiring at least #{ver}" unless
>    RUBY_VERSION.scan(/d+/).map! {|x|x.to_i} >=
>       ver.scan(/d+/).map! {|x|x.to_i}
> end
>
> Not really a one liner...

(What, no inject? :-)  I don't think Array has >= though.


David

-- 
David A. Black (dblack / wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black