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

properly deprecate the options hash #1187

Merged
merged 3 commits into from
Jun 23, 2019
Merged
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
26 changes: 19 additions & 7 deletions lib/rouge/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,29 @@ def reset!
# @option opts :continue
# Continue the lex from the previous state (i.e. don't call #reset!)
#
# @note The use of `opts` has been deprecated. A warning is issued if run
# with `$VERBOSE` set to true.
def lex(string, opts={}, &b)
unless opts.nil?
warn 'The use of opts with Lexer.lex is deprecated' if $VERBOSE
# @note The use of :continue => true has been deprecated. A warning is
# issued if run with `$VERBOSE` set to true.
#
# @note The use of arbitrary `opts` has never been supported, but we
# previously ignored them with no error. We now warn unconditionally.
def lex(string, opts=nil, &b)
if opts
if (opts.keys - [:continue]).size > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use Array#empty? here:

Suggested change
if (opts.keys - [:continue]).size > 0
unless (opts.keys - [:continue]).empty?

# improper use of options hash
warn('Improper use of Lexer#lex - this method does not receive options.' +
' This will become an error in a future version.')
end

if opts[:continue]
warn '`lex :continue => true` is deprecated, please use #continue_lex instead'
return continue_lex(string, &b)
end
end

return enum_for(:lex, string, opts) unless block_given?
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the culprit for the warning.

return enum_for(:lex, string) unless block_given?

Lexer.assert_utf8!(string)
reset! unless opts[:continue]
reset!

continue_lex(string, &b)
end
Expand Down