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

Decouple RubyLex from prompt and line_no #701

Merged
merged 3 commits into from
Oct 12, 2023

Conversation

tompng
Copy link
Member

@tompng tompng commented Aug 30, 2023

Removes the last RubyLex's instance variable @prompt and @line_no.

Reason:
@line_no is completely controlled by IRB::Irb with @scanner.increase_line_no. It should be IRB::Irb's instance variable.
@scanner.set_prompt do end and @scanner.prompt(args) seems roundabout.
I wanted to remove save_prompt_to_context_io because the flow is complex and hard to understand.

After deleting @prompt and @line_no from RubyLex, RubyLex will have no state at all. RubyLex does not have to be a class anymore.

@tompng tompng force-pushed the stateless_rubylex branch from a9744da to ec52279 Compare October 11, 2023 14:56
@tompng tompng force-pushed the stateless_rubylex branch from ec52279 to f1aef4a Compare October 11, 2023 15:05
@tompng tompng marked this pull request as ready for review October 11, 2023 15:12
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Currently we don't declare private methods under IRB::Irb, but I think these 2 prompt methods can be the first 2. WDYT?
While we expect Irb to be a private component, it's still relatively easy to retrieve (e.g. with irb_context.irb) and could be used by us in other gems too (e.g. ruby/debug#1024). So making some methods private could ideally make people think twice before calling them.

lib/irb.rb Outdated Show resolved Hide resolved
@tompng tompng merged commit 1ceb97f into ruby:master Oct 12, 2023
24 checks passed
@tompng tompng deleted the stateless_rubylex branch October 12, 2023 12:53
matzbot pushed a commit to ruby/ruby that referenced this pull request Oct 12, 2023
(ruby/irb#701)

* Remove instance variable prompt and line_no from RubyLex

* Fix prompt test

* Rename prompt generating method and make it private

ruby/irb@1ceb97fe2e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants