Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Handle keyword arguments for Ruby 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kodnin committed Aug 11, 2021
1 parent 14cb0af commit 97c1ccf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/image_vise/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ def empty?
@ops.empty?
end

def method_missing(method_name, args = {}, &blk)
operator_builder = ImageVise.operator_from(method_name)
self << operator_builder.new(**args)
if RUBY_VERSION.starts_with?("2.6")
def method_missing(method_name, *args, &blk)
operator_builder = ImageVise.operator_from(method_name)
self << operator_builder.new(*args)
end
else
def method_missing(method_name, args = {}, &blk)
operator_builder = ImageVise.operator_from(method_name)
self << operator_builder.new(**args)
end
end

def respond_to_missing?(method_name, *a)
Expand Down

2 comments on commit 97c1ccf

@fabioperrella
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked it! It is clear that it is a thing related to the Ruby version

@kodnin
Copy link
Contributor Author

@kodnin kodnin commented on 97c1ccf Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked it! It is clear that it is a thing related to the Ruby version

Yeah, but you repeat the whole definition with another parameter list and slightly different body. We could combine your solution with args.empty? && RUBY_VERSION.start_with?("2.6") though, but it's not needed.

Please sign in to comment.