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

Change the way common methods are mixed in to TypeScript-based lexers #1527

Merged
merged 1 commit into from May 30, 2020

Conversation

pyrmont
Copy link
Contributor

@pyrmont pyrmont commented May 30, 2020

Sometimes it makes sense for a Rouge lexer to inherit methods from more than one class. Ruby does not have multiple class inheritance and so the idiomatic solution in Rouge is to extract the methods that should be shared into a common module that can be mixed in to the relevant lexers.

A Ruby module can be mixed in via either calling include or extend. If the module is mixed in via include, then the methods are added as instance methods of the mixing class. If the module is mixed in via extend, the methods are added to the singleton class of the mixing class. Given the way Rouge is architected, it is more correct for the common module to be extended (not doing so can cause issues with overloading methods).

This PR updates the TypeScript and TSX lexers to mix in the TypescriptCommon module by calling extend rather than include.

@pyrmont pyrmont added the needs-review The PR needs to be reviewed label May 30, 2020
@pyrmont pyrmont merged commit e14b77a into rouge-ruby:master May 30, 2020
@pyrmont pyrmont deleted the bugfix.typescript-common-module branch May 30, 2020 18:57
@pyrmont pyrmont removed the needs-review The PR needs to be reviewed label May 30, 2020
mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
…rouge-ruby#1527)

Sometimes it makes sense for a Rouge lexer to inherit methods from more
than one class. Ruby does not have multiple class inheritance and so
the idiomatic solution in Rouge is to extract the methods that should
be shared into a common module that can be mixed in to the relevant
lexers.

A Ruby module can be mixed in via either calling `include` or `extend`.
If the module is mixed in via `include`, then the methods are added as
instance methods of the mixing class. If the module is mixed in via
`extend`, the methods are added to the singleton class of the mixing
class. Given the way Rouge is architected, it is more correct for the
common module to be extended (not doing so can cause issues with
overloading methods).

This commit updates the TypeScript and TSX lexers to mix in the
`TypescriptCommon` module by calling `extend` rather than `include`.
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

1 participant