-
Notifications
You must be signed in to change notification settings - Fork 175
Handle String-like and IO-like objects for Ripper.sexp #3891
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -480,7 +480,17 @@ def self.lex_state_name(state) | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # Create a new Translation::Ripper object with the given source. | ||||||||||||||||||||||||||||||||||||||||||||||||
| def initialize(source, filename = "(ripper)", lineno = 1) | ||||||||||||||||||||||||||||||||||||||||||||||||
| @source = source | ||||||||||||||||||||||||||||||||||||||||||||||||
| if source.is_a?(IO) | ||||||||||||||||||||||||||||||||||||||||||||||||
| @source = source.read | ||||||||||||||||||||||||||||||||||||||||||||||||
| elsif source.respond_to?(:gets) | ||||||||||||||||||||||||||||||||||||||||||||||||
| @source = +"" | ||||||||||||||||||||||||||||||||||||||||||||||||
| while line = source.gets | ||||||||||||||||||||||||||||||||||||||||||||||||
| @source << line | ||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||
| @source = source.to_str | ||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||
This comment was marked as duplicate.
Sorry, something went wrong.
Comment on lines
+483
to
+492
Collaborator
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. Maybe like this to skip respond_to when it's already a string? It's better for cruby but a bit more complex. I remeber something like this being done in the json gem.
Suggested change
Member
Author
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 think the |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| @filename = filename | ||||||||||||||||||||||||||||||||||||||||||||||||
| @lineno = lineno | ||||||||||||||||||||||||||||||||||||||||||||||||
| @column = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
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.
This could be backed by
Prism.parse_streambut since we need the whole source anyways I think this is fine. BTW, wouldn't work for thegetscase since prism also expectseof?to be present