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

Extracted source continues to next expression on same line #28

Open
sawa opened this issue Feb 10, 2015 · 4 comments
Open

Extracted source continues to next expression on same line #28

sawa opened this issue Feb 10, 2015 · 4 comments

Comments

@sawa
Copy link

sawa commented Feb 10, 2015

Extracted source continues to the next expression on the same line

def foo; end; def bar
  "baz"
end

method(:foo).source.display

output:

def foo; end; def bar
  "baz"
end

I expected:

def foo; end; def bar

Is this bug or feature?

@banister
Copy link
Owner

It's because we use a simplistic approach to extracting the code, we read line by line looking for complete expressions. This works in 90% of cases as users don't typically define more than one method on a line.

@rf-
Copy link
Collaborator

rf- commented Feb 10, 2015

I guess it wouldn't be very hard to try advancing by semicolon-separated chunks and not just complete lines.

On Tue, Feb 10, 2015 at 9:06 AM, John Mair [email protected]
wrote:

It's because we use a simplistic approach to extracting the code, we read line by line looking for complete expressions. This works in 90% of cases as users don't typically define more than one method on a line.

Reply to this email directly or view it on GitHub:
#28 (comment)

@sawa
Copy link
Author

sawa commented Feb 11, 2015

Since you are not aiming for dynamically defined methods, all method definitions will follow def ... end syntax. Therefore, you don't even have to go through line by line. Rather, you can go through each positions that ends with end, whether or not that is in the middle of a line. That would in general be more efficient since you can skip line, and at the same time be more accurate to handle cases like this.

@rf-
Copy link
Collaborator

rf- commented Feb 11, 2015

We actually do support dynamically-defined methods. It's also not uncommon for a source_location to point to something like an attr_accessor call.

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

No branches or pull requests

3 participants