Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make keyword arguments delegation compatible with ruby v3 #70

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions libraries/choregraphie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ def initialize(name, &block)
# read all available primitives and make them available with a method
# using their name. It allows to call `check_file '/tmp/titi'` to
# instantiate the CheckFile primitive
delegated_args = RUBY_VERSION < '3' ? '*args, &block' : '*args, **kwargs, &block'
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and below please use RUBY_VERSION.to_i < 3; your code works ... until we get to ruby 10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do! I hope we will able to drop ruby 2.7 support and remove this fix before Ruby v10, but yes :)

Primitive.all.each do |klass|
instance_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{klass.primitive_name}(*args, &block)
primitive = ::#{klass}.new(*args, &block)
def #{klass.primitive_name}(#{delegated_args})
primitive = ::#{klass}.new(#{delegated_args})
@primitives << primitive
primitive.register(self)
end
Expand Down Expand Up @@ -75,8 +76,14 @@ def #{klass.primitive_name}(*args, &block)
instance_eval(&block)
end

def method_missing(method, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@self_before_instance_eval.send method, *args, &block
if RUBY_VERSION < '3'
def method_missing(method, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@self_before_instance_eval.send method, *args, &block
end
else
def method_missing(method, *args, **kwargs, &block) # rubocop:disable Style/MissingRespondToMissing
@self_before_instance_eval.send method, *args, **kwargs, &block
end
end

def cleanup_block_name(resource_name)
Expand Down