What the "reject" method in the ruby optionparser does?

62 views Asked by At

There is an "accept" example in the documentation. But i can't figure out what is the use of the "reject" method? Can somebody explain the sense and give some usage example?

I tried to read the source but no luck.

1

There are 1 answers

2
Amadan On

It simply undoes accept.

For example, using the snippet in documentation demonstrating accept:

op.accept(User) do |user_id|
  find_user user_id.to_i
end

If after that we issue op.reject(User), User will no longer be accepted — as if op.accept(User) ... was never specified. If we try, the code would generate unsupported argument type: User (ArgumentError).