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

Implement Binding#local_variables and Binding#receiver #3352

Merged
merged 1 commit into from
Mar 10, 2015

Conversation

ruipserra
Copy link
Contributor

Hi everyone, this PR implements Binding#local_variables and Binding#receiver.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@@ -54,4 +54,12 @@ def eval(expr, filename=nil, lineno=nil)

Kernel.eval(expr, self, filename, lineno)
end

def local_variables
eval('local_variables')
Copy link
Contributor

Choose a reason for hiding this comment

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

Euh, we shouldn't need (nor want) the use of eval here. If I'm not mistaken the code currently used for Kernel.local_variables should be usable in this context, either in the form of a copy-paste (meh) or by using a helper method (one that takes a Rubinius::VariableScope).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yorickpeterse Indeed, the use of eval is a bit gross. The reason behind it was only to avoid duplicating Kernel.local_variables. Would pushing this logic into Rubinius::VariableScope be an acceptable option?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, from the top of my head I think this can be reduced down to the following:

def local_variables
  scope = Rubinius::VariableScope.of_sender

  scope.local_variables
end

This can then be used in both Kernel#local_variables and Binding#local_variables.

Copy link
Member

Choose a reason for hiding this comment

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

Binding already has its VariableScope - it's in the @variables ivar, from Binding.setup.

jemc added a commit that referenced this pull request Mar 10, 2015
Implement Binding#local_variables and Binding#receiver
@jemc jemc merged commit 8cb3959 into rubinius:2.2 Mar 10, 2015
end

def receiver
@self
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does @self originate from? Is this not supposed to just return self (minus the @)?

Copy link
Member

Choose a reason for hiding this comment

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

It should indeed be @self here - self would return the Binding instance itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I now see this is set by Rubinius::VariableScope#self=, which wasn't entirely obvious to find.

Copy link
Member

Choose a reason for hiding this comment

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

To make it more obvious for others in the future, it seems like the @self ivar could be renamed to @receiver, so that Binding#receiver would just be an attr_reader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jemc I agree. The attr_accessor :self could be replaced with regular
def self=(recv) ... and def self ... methods refering to @receiver, which would make the purpose of the ivar clearer, without breaking client code depending on self.

@yorickpeterse
Copy link
Contributor

@jemc I'm reverting this, see my notes.

yorickpeterse pushed a commit that referenced this pull request Mar 10, 2015
yorickpeterse pushed a commit that referenced this pull request Mar 10, 2015
@ruipserra
Copy link
Contributor Author

Continued at #3354

yorickpeterse pushed a commit that referenced this pull request Mar 12, 2015
yorickpeterse pushed a commit that referenced this pull request May 25, 2015
yorickpeterse pushed a commit that referenced this pull request Jul 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants