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

used 'Enumerator#with_index' to detect lineno. #1615

Merged
merged 2 commits into from
Oct 30, 2020

Conversation

fumihumi
Copy link
Contributor

used 'Enumerator#with_index' to detect lineno.

before: Defined a variable called lineno to count up for each loop.
after: Fixed it.' Enumerator#with_index'.

Rouge::Formatters is often referenced by developers when creating Custom Formatters, so I think it should be written in a better Ruby way.

and fix block scope variable name.(Adjusted variable names to match those used in other files.)

* 'tokens_in_line' -> 'line_tokens'
The names of variables used as "line_tokens" in html_line_table and html_linewise files should be changed to match the names of those files.
@jneen
Copy link
Member

jneen commented Oct 25, 2020

+1 from me. @fumihumi which version of Ruby added this method?

@pyrmont
Copy link
Contributor

pyrmont commented Oct 25, 2020

@jneen The method that accepts an index was added in 1.9.2, I think (source).

@fumihumi
Copy link
Contributor Author

fumihumi commented Oct 26, 2020

@jneen cc @pyrmont
Thanks for replying.

I used https://github.com/akr/all-ruby to check it.
According to this, it seems to have been added in ruby-1.8.7. (version 1.8.7 did not support argument-based offsets)
According to this, it seems to have been added in ruby-1.9.2

If you want to run it by hand, you can check it with the following command

$ docker run --rm -e 'ALL_RUBY_SINCE=ruby-1.8' -e 'ALL_RUBY_SHOW_DUP=yes' rubylang/all-ruby . /all-ruby -e 'a=[11,22,33,44,55].to_enum; a.with_index(1) { |val,index| puts "index: #{index} for #{val}" }'

result: https://gist.github.com/fumihumi/d4966df51852a08b8807ba9ea0dd585b

Thank you!

@jneen jneen merged commit 6ef0daa into rouge-ruby:master Oct 30, 2020
@fumihumi fumihumi deleted the fixes-lineno-detection branch October 30, 2020 02:30
mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
* used 'Enumerator#with_index' to detect lineno.

* Changing variable names

* 'tokens_in_line' -> 'line_tokens'
The names of variables used as "line_tokens" in html_line_table and html_linewise files should be changed to match the names of those files.
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