8000 Extract version number from the source · ruby/optparse@1dd974a · GitHub
[go: up one dir, main page]

Skip to content

Commit 1dd974a

Browse files
nobuhsbt
authored andcommitted
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.
1 parent d77e777 commit 1dd974a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

optparse.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
# frozen_string_literal: true
2+
13
name = File.basename(__FILE__, ".gemspec")
2-
version = nil
3-
["lib", ".."].find do |dir|
4-
version = File.foreach(File.join(__dir__, dir, "#{name}.rb")) do |line|
4+
version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
5+
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
56
/^\s*OptionParser::Version\s*=\s*"(.*)"/ =~ line and break $1
67
end rescue nil
78
end

0 commit comments

Comments
 (0)
0