Skip to content

Commit

Permalink
Slightly less repetitive
Browse files Browse the repository at this point in the history
  • Loading branch information
dim committed Aug 10, 2020
1 parent c4ceaf3 commit 67013a3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/grape/middleware/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Middleware
# It allows to insert and insert after
class Stack
class Middleware
use_ruby2_keywords = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')

attr_reader :args, :opts, :block, :klass

def initialize(klass, *args, **opts, &block)
Expand All @@ -17,13 +19,13 @@ def initialize(klass, *args, **opts, &block)

def use_in(builder)
block ? builder.use(klass, *args, **opts, &block) : builder.use(klass, *args, **opts)
end if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
end if use_ruby2_keywords

def use_in(builder)
args = m.args
args += [m.opts] unless m.opts.empty?
block ? builder.use(klass, *args, &block) : builder.use(klass, *args)
end if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
end unless use_ruby2_keywords

def name
klass.name
Expand Down

0 comments on commit 67013a3

Please sign in to comment.