Skip to content

Commit

Permalink
Merge pull request #80 from casperisfine/fstr
Browse files Browse the repository at this point in the history
Fix compatibility with frozen-string-literal and newer rubies
  • Loading branch information
kyrylo authored Apr 15, 2024
2 parents 81d039c + 54c91e4 commit 2d130a4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Gemfile.lock

4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
source 'https://rubygems.org'

gemspec

gem "rake"
gem "rspec"
6 changes: 3 additions & 3 deletions lib/method_source/code_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -104,15 +104,15 @@ def extract_first_expression(lines, consume=0, &block)
# @param [Array<String>] lines
# @return [String]
def extract_last_comment(lines)
buffer = ""
buffer = +""

lines.each do |line|
# Add any line that is a valid ruby comment,
# but clear as soon as we hit a non comment line.
if (line =~ /^\s*#/) || (line =~ /^\s*$/)
buffer << line.lstrip
else
buffer.replace("")
buffer.clear
end
end

Expand Down
15 changes: 0 additions & 15 deletions method_source.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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<rspec>.freeze, ["~> 3.6"])
s.add_development_dependency(%q<rake>.freeze, ["~> 0.9"])
else
s.add_dependency(%q<rspec>.freeze, ["~> 3.6"])
s.add_dependency(%q<rake>.freeze, ["~> 0.9"])
end
else
s.add_dependency(%q<rspec>.freeze, ["~> 3.6"])
s.add_dependency(%q<rake>.freeze, ["~> 0.9"])
end
end

0 comments on commit 2d130a4

Please sign in to comment.