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

Symbol procs as groups don't work as expected. #405

Closed
supersam654 opened this issue Apr 12, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@supersam654
Copy link

commented Apr 12, 2019

Consider these two groups:

Flipper.register(:working) do |actor|
  actor.admin?
end

Flipper.register(:broken, &:admin?)

class User
  def admin?
    true
  end
end

The first group works as expected. However, the second group raises an exception about passing the wrong number of arguments to admin? even though it appears to be syntactic sugar for the first one.

I did some digging and the problem appears to be at https://github.com/jnunemaker/flipper/blob/master/lib/flipper/types/group.rb#L17.

Notably, the arity of the symbol proc is -1 while the arity of the regular block is 1.

def print_arity(&block)
  puts block.arity
end

print_arity(&:to_s) # Prints -1
print_arity { |a| a.to_s } # Prints 1

With all of that said, I'm not very familiar with arity checking in Ruby. However, it seems that checking the absolute value of the arity would work in this situation. If someone else thinks this is a good idea, I'd be more than happy to make the (tiny) PR for this.

@jnunemaker

This comment has been minimized.

Copy link
Owner

commented Apr 20, 2019

Definitely open to a PR with a spec/fix.

@thetimbanks

This comment has been minimized.

Copy link
Collaborator

commented May 11, 2019

Closing since this was resolved by #406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.