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

Add method overload of OptionParser#on #1114

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions stdlib/optparse/0/optparse.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,10 @@ class OptionParser
#
def on: (*String params) ?{ (*untyped) -> untyped } -> self
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
| (String short_params, String long_params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
| (*String params, Proc | Method handler) -> self
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self
| (String short_params, String long_params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self

# <!--
# rdoc-file=lib/optparse.rb
Expand All @@ -696,8 +698,10 @@ class OptionParser
#
def on_head: (*String params) ?{ (*untyped) -> untyped } -> self
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
| (String short_params, String long_params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
| (*String params, Proc | Method handler) -> self
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self
| (String short_params, String long_params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self

# <!--
# rdoc-file=lib/optparse.rb
Expand All @@ -715,8 +719,10 @@ class OptionParser
#
def on_tail: (*String params) ?{ (*untyped) -> untyped } -> self
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
| (String short_params, String long_params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc) ?{ (*untyped) -> untyped } -> self
| (*String params, Proc | Method handler) -> self
| (String params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self
| (String short_params, String long_params, Class | Array[String] | Hash[Symbol, untyped] | Regexp obj, ?String desc, Proc | Method handler) -> self

# <!--
# rdoc-file=lib/optparse.rb
Expand Down
12 changes: 12 additions & 0 deletions test/stdlib/OptionParser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,41 @@ def test_on
assert_send_type "(*String) -> self", opt, :on, '-a'
assert_send_type "(String, Class) -> self", opt, :on, '-a', Array
assert_send_type "(String, Class, String) -> self", opt, :on, '-a', Array, 'description'
assert_send_type "(String, String, Class, String) -> self", opt, :on, '-a', '--all', Array, 'description'
assert_send_type "(String, Array[String]) -> self", opt, :on, '-a', ['foo', 'bar']
assert_send_type "(String, String, Array[String]) -> self", opt, :on, '-a', '--all', ['foo', 'bar']
assert_send_type "(String, Hash[Symbol, untyped]) -> self", opt, :on, '-a', {foo: 1, bar: 2}
assert_send_type "(String, String, Hash[Symbol, untyped]) -> self", opt, :on, '-a', '--all', {foo: 1, bar: 2}
assert_send_type "(String, Regexp) -> self", opt, :on, '-a', /foo/
assert_send_type "(String, String, Regexp) -> self", opt, :on, '-a', '--all', /foo/
assert_send_type "(*String, Proc) -> self", opt, :on, '-a', proc {}
end

def test_on_head
assert_send_type "(*String) -> self", opt, :on_head, '-a'
assert_send_type "(String, Class) -> self", opt, :on_head, '-a', Array
assert_send_type "(String, Class, String) -> self", opt, :on_head, '-a', Array, 'description'
assert_send_type "(String, String, Class, String) -> self", opt, :on_head, '-a', '--all', Array, 'description'
assert_send_type "(String, Array[String]) -> self", opt, :on_head, '-a', ['foo', 'bar']
assert_send_type "(String, String, Array[String]) -> self", opt, :on_head, '-a', '--all', ['foo', 'bar']
assert_send_type "(String, Hash[Symbol, untyped]) -> self", opt, :on_head, '-a', {foo: 1, bar: 2}
assert_send_type "(String, String, Hash[Symbol, untyped]) -> self", opt, :on_head, '-a', '--all', {foo: 1, bar: 2}
assert_send_type "(String, Regexp) -> self", opt, :on_head, '-a', /foo/
assert_send_type "(String, String, Regexp) -> self", opt, :on_head, '-a', '--all', /foo/
assert_send_type "(*String, Proc) -> self", opt, :on_head, '-a', proc {}
end

def test_on_tail
assert_send_type "(*String) -> self", opt, :on_tail, '-a'
assert_send_type "(String, Class) -> self", opt, :on_tail, '-a', Array
assert_send_type "(String, Class, String) -> self", opt, :on_tail, '-a', Array, 'description'
assert_send_type "(String, String, Class, String) -> self", opt, :on_tail, '-a', '--all', Array, 'description'
assert_send_type "(String, Array[String]) -> self", opt, :on_tail, '-a', ['foo', 'bar']
assert_send_type "(String, String, Array[String]) -> self", opt, :on_tail, '-a', '--all', ['foo', 'bar']
assert_send_type "(String, Hash[Symbol, untyped]) -> self", opt, :on_tail, '-a', {foo: 1, bar: 2}
assert_send_type "(String, String, Hash[Symbol, untyped]) -> self", opt, :on_tail, '-a', '--all', {foo: 1, bar: 2}
assert_send_type "(String, Regexp) -> self", opt, :on_tail, '-a', /foo/
assert_send_type "(String, String, Regexp) -> self", opt, :on_tail, '-a', '--all', /foo/
assert_send_type "(*String, Proc) -> self", opt, :on_tail, '-a', proc {}
end

Expand Down