Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ruby3-and-kwargs-support' into r…
Browse files Browse the repository at this point in the history
…uby3-and-kwargs-support
  • Loading branch information
NourEldinShobier committed Jan 10, 2024
2 parents a7f0aa1 + f310832 commit 7df9d40
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions lib/delayed/performable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,18 @@ def kwargs
@kwargs || {}
end

# In ruby 3 we need to explicitly separate regular args from the keyword-args.
if RUBY_VERSION >= '3.0'
def perform
object.send(method_name, *args, **kwargs) if object
end
else
# On ruby 2, rely on the implicit conversion from a hash to kwargs
def perform
return unless object

arguments = args.is_a?(Array) ? args : [args]

if kwargs.present?
object.send(method_name, *arguments, kwargs)
else
object.send(method_name, *arguments)
end
end
def perform
object.send(method_name, *args, **kwargs) if object
end

def method(sym)
object.method(sym)
end
method_def = []
location = caller_locations(1, 1).first
file = location.path
line = location.lineno
definition = RUBY_VERSION >= '2.7' ? '...' : '*args, &block'
method_def <<
"def method_missing(#{definition})" \
" object.send(#{definition})" \
'end'
module_eval(method_def.join(';'), file, line)

# rubocop:disable MethodMissing
def method_missing(symbol, *args, **kwargs)
object.send(symbol, *args, **kwargs)
end
# rubocop:enable MethodMissing

def respond_to?(symbol, include_private = false)
Expand Down

0 comments on commit 7df9d40

Please sign in to comment.