Helper methods without object polluting#1216
Draft
tompng wants to merge 1 commit into
Draft
Conversation
eb3d4c0 to
827cbc2
Compare
Instead of defining helper method to current workspace object, modify the input code to directly call helper method defined in a container object. `p conf.ap_name` will be modified to `p ::IRB::HelperMethod::Container.conf.ap_name`. Also implements highlighting, completion, and document dialog for helper methods.
827cbc2 to
687e677
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instead of defining helper method to current workspace object, modify the input code to directly call helper method defined in a container object.
p conf.ap_namewill be modified top ::IRB::HelperMethod::Container.conf.ap_name.Problem
Main objects are polluted by helper methods.
Especially when using with
stepdebug command, many objects were polluted.Polluted object may break application/library code that has
respond_to?checks.These codes were found in GitHub code search:
respond_to?(:conf)respond_to?(:helper)respond_to?(:app)respond_to?(:controller)respond_to?(:reload!)respond_to?(:new_session).Helper methods were method call to a polluted object, dynamically determined. We can't autocomplete or show a document dialog for helper methods
Changes
Before: Calling
confon polluted object is a helper method call, dynamically determined.After:
confwithout receiver is always helper method call.confwith receiver, statically determined.obj.instance_eval { conf }obj.conftap(&:conf)self.confinstance_eval { send(:conf) }self.send(:conf)eval("conf")eval("conf")self.confself.confself.tap { it.conf }self.confclass A; conf; endA.confHelper method calls are colored BOLD just like commands. I think this syntax highlighting is required to avoid confusion.

Also implements completion and document dialog for helper method.
Pros/Cons
Pros
No polluting
Cons
confand other helper methods such ascontrollerapp,reload!without receiver will be always treated as helper method, even ifselfhave the same method.Another options