From: dblack@... Date: 2006-03-25T21:42:26+09:00 Subject: Re: require a certain version of the ruby interpreter Hi -- On Sat, 25 Mar 2006, Pit Capitain wrote: > dblack@wobblini.net schrieb: >> Here's yet another variation on the theme. (I thought I'd posted this >> in my previous post but I didn't.) >> >> require 'scanf' >> def ensure_version(need) >> need.scanf("%d.%d.%d"). >> zip(RUBY_VERSION.scanf("%d.%d.%d")).any? do |a,b| >> a > b >> end and raise "Requires at least #{need}" >> end > > Both the solutions using any? aren't correct: > > puts RUBY_VERSION # => 1.8.4 > ensure_version "1.6.8" # => Requires at least 1.6.8 (RuntimeError) Whoops. I guess the order matters: one would want to peel off numbers from the left until there's an inequal pair. I've gone back to feeling lazy enough to piggy-back on the assurance of one digit per field: def ensure_version(need) raise "Requires ruby #{need}" if need < RUBY_VERSION end 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