-
-
Notifications
You must be signed in to change notification settings - Fork 54
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 delimiters' and related predicates for
RegexpNode`
#41
Changes from 3 commits
61e9e69
6c3393d
7fc0d09
772b247
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,26 @@ def content | |
children.select(&:str_type?).map(&:str_content).join | ||
end | ||
|
||
# @return [Bool] if the regexp is a /.../ literal | ||
def slash_literal? | ||
loc.begin.source == '/' | ||
end | ||
|
||
# @return [Bool] if the regexp is a %r{...} literal (using any delimiters) | ||
def percent_r_literal? | ||
!slash_literal? | ||
end | ||
|
||
# @return [String] the regexp delimiters (without %r) | ||
def delimiters | ||
[loc.begin.source[-1], loc.end.source[0]] | ||
end | ||
|
||
# @return [Bool] if char is one of the delimiters | ||
def delimiter?(char) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you can also add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea - I took a quick look for related predicates used by RuboCop, so added those too, let me know what you think |
||
delimiters.include?(char) | ||
end | ||
|
||
# @return [Bool] if regexp contains interpolation | ||
def interpolation? | ||
children.any?(&:begin_type?) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've made a small mistake with the backticks here.