Skip to content

Commit 257d7dc

Browse files
committed
Convert OptParse#make_switch to accept keyword arguments
1 parent 9a784a8 commit 257d7dc

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/optparse.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,8 @@ def to_a; summarize("#{banner}".split(/^/)) end
14701470
#
14711471
# :include: ../doc/optparse/creates_option.rdoc
14721472
#
1473-
def make_switch(opts, block = nil)
1473+
def make_switch(opts, block = nil, **kwopts)
1474+
opts.append kwopts # Append keyword options to maintain backwards compatibility
14741475
short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
14751476
ldesc, sdesc, desc, arg = [], [], []
14761477
default_style = Switch::NoArgument
@@ -1628,8 +1629,8 @@ def make_switch(opts, block = nil)
16281629
#
16291630
# :include: ../doc/optparse/creates_option.rdoc
16301631
#
1631-
def define(*opts, &block)
1632-
top.append(*(sw = make_switch(opts, block)))
1632+
def define(*opts, **kwopts, &block)
1633+
top.append(*(sw = make_switch(opts, block, **kwopts)))
16331634
sw[0]
16341635
end
16351636

@@ -1638,8 +1639,8 @@ def define(*opts, &block)
16381639
#
16391640
# :include: ../doc/optparse/creates_option.rdoc
16401641
#
1641-
def on(*opts, &block)
1642-
define(*opts, &block)
1642+
def on(*opts, **kwopts, &block)
1643+
define(*opts, **kwopts, &block)
16431644
self
16441645
end
16451646
alias def_option define
@@ -1649,8 +1650,8 @@ def on(*opts, &block)
16491650
#
16501651
# :include: ../doc/optparse/creates_option.rdoc
16511652
#
1652-
def define_head(*opts, &block)
1653-
top.prepend(*(sw = make_switch(opts, block)))
1653+
def define_head(*opts, **kwopts, &block)
1654+
top.prepend(*(sw = make_switch(opts, block, **kwopts)))
16541655
sw[0]
16551656
end
16561657

@@ -1661,8 +1662,8 @@ def define_head(*opts, &block)
16611662
#
16621663
# The new option is added at the head of the summary.
16631664
#
1664-
def on_head(*opts, &block)
1665-
define_head(*opts, &block)
1665+
def on_head(*opts, **kwopts, &block)
1666+
define_head(*opts, **kwopts, &block)
16661667
self
16671668
end
16681669
alias def_head_option define_head
@@ -1672,8 +1673,8 @@ def on_head(*opts, &block)
16721673
#
16731674
# :include: ../doc/optparse/creates_option.rdoc
16741675
#
1675-
def define_tail(*opts, &block)
1676-
base.append(*(sw = make_switch(opts, block)))
1676+
def define_tail(*opts, **kwopts, &block)
1677+
base.append(*(sw = make_switch(opts, block, **kwopts)))
16771678
sw[0]
16781679
end
16791680

@@ -1685,8 +1686,8 @@ def define_tail(*opts, &block)
16851686
#
16861687
# The new option is added at the tail of the summary.
16871688
#
1688-
def on_tail(*opts, &block)
1689-
define_tail(*opts, &block)
1689+
def on_tail(*opts, **kwopts, &block)
1690+
define_tail(*opts, **kwopts, &block)
16901691
self
16911692
end
16921693
alias def_tail_option define_tail

0 commit comments

Comments
 (0)