From 54c91e40fc11df07b77e39ee3cb65b31078d29de Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 28 Mar 2024 13:08:25 +0100 Subject: [PATCH] Fix compatibility with frozen-string-literal and newer rubies Also setup CI Co-Authored-By: Pat Allan --- .github/workflows/main.yml | 25 +++++++++++++++++++++++++ .gitignore | 2 ++ Gemfile | 4 ++++ lib/method_source/code_helpers.rb | 6 +++--- method_source.gemspec | 15 --------------- 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1c2e19a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,25 @@ +name: Ruby + +on: ['push'] + +jobs: + build: + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} + strategy: + matrix: + ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', 'head'] + rubyopt: [''] + include: + - ruby: '3.3' + rubyopt: "--enable-frozen-string-literal --debug-frozen-string-literal" + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run the default task + run: bundle exec rake RUBYOPT="${{ matrix.rubyopt }}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80e3957 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Gemfile.lock + diff --git a/Gemfile b/Gemfile index 851fabc..71d74ff 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,6 @@ source 'https://rubygems.org' + gemspec + +gem "rake" +gem "rspec" diff --git a/lib/method_source/code_helpers.rb b/lib/method_source/code_helpers.rb index ccf054a..4185c18 100644 --- a/lib/method_source/code_helpers.rb +++ b/lib/method_source/code_helpers.rb @@ -90,7 +90,7 @@ def complete_expression?(str) # @return [String] a valid ruby expression # @raise [SyntaxError] def extract_first_expression(lines, consume=0, &block) - code = consume.zero? ? "" : lines.slice!(0..(consume - 1)).join + code = consume.zero? ? +"" : lines.slice!(0..(consume - 1)).join lines.each do |v| code << v @@ -104,7 +104,7 @@ def extract_first_expression(lines, consume=0, &block) # @param [Array] lines # @return [String] def extract_last_comment(lines) - buffer = "" + buffer = +"" lines.each do |line| # Add any line that is a valid ruby comment, @@ -112,7 +112,7 @@ def extract_last_comment(lines) if (line =~ /^\s*#/) || (line =~ /^\s*$/) buffer << line.lstrip else - buffer.replace("") + buffer.clear end end diff --git a/method_source.gemspec b/method_source.gemspec index 8acb290..a400823 100644 --- a/method_source.gemspec +++ b/method_source.gemspec @@ -16,19 +16,4 @@ Gem::Specification.new do |s| s.licenses = ["MIT".freeze] s.summary = "retrieve the sourcecode for a method".freeze s.test_files = ["spec/method_source/code_helpers_spec.rb".freeze, "spec/method_source_spec.rb".freeze, "spec/spec_helper.rb".freeze] - - if s.respond_to? :specification_version then - s.specification_version = 4 - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_development_dependency(%q.freeze, ["~> 3.6"]) - s.add_development_dependency(%q.freeze, ["~> 0.9"]) - else - s.add_dependency(%q.freeze, ["~> 3.6"]) - s.add_dependency(%q.freeze, ["~> 0.9"]) - end - else - s.add_dependency(%q.freeze, ["~> 3.6"]) - s.add_dependency(%q.freeze, ["~> 0.9"]) - end end