From b2d96abb42abbe2e01f010ffc9ac51f0f9a50002 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 29 Jul 2020 00:31:52 +0900 Subject: Extract version number from the source "requiring version.rb" strategy has some issues. - cannot work when cross-compiling - often introduces wrong namespace - must know the superclasses - costs at each runtime than at build-time etc. --- lib/optparse/optparse.gemspec | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/optparse') diff --git a/lib/optparse/optparse.gemspec b/lib/optparse/optparse.gemspec index 25f81c08bb..3de0c07f43 100644 --- a/lib/optparse/optparse.gemspec +++ b/lib/optparse/optparse.gemspec @@ -1,7 +1,8 @@ +# frozen_string_literal: true + name = File.basename(__FILE__, ".gemspec") -version = nil -["lib", ".."].find do |dir| - version = File.foreach(File.join(__dir__, dir, "#{name}.rb")) do |line| +version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir| + break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line| /^\s*OptionParser::Version\s*=\s*"(.*)"/ =~ line and break $1 end rescue nil end -- cgit v1.2.3