Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Some refactor #11

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Some refactor #11

wants to merge 7 commits into from

Conversation

chancancode
Copy link

Hello, this is very cool project and a great use case for Helix!

I pulled the code to play with it a little bit locally. While I was at that I found some small improvements so I thought I should submit a PR.

I arranged the commits (roughly) from the safest to potentially undesirable changes. The later commits are more suggestions along the lines of "Hey, in case you didn't know, you can do this now!" – so feel free to cherry-pick out anything that is not acceptable to you.

Let me know if you have any questions. By the way, if you have any questions or suggestions for Helix please feel free to let me know (or open an issue). I would also like to know what are some missing features you might need for this library so we know how to prioritize them.

Thanks for trying Helix!!

This will be turned into a Ruby exception which is the idomatic
error-handling protocol in Ruby.

(It doesn't seem like the result could ever be `false`; should it be
a `Result<(), String>` instead?)
The Helix coercion for strings already need to do a copy to turn
them into Ruby strings, so the extra clone is unnecessary.
Introduced in [RFC #1682][1], available since Rust 1.17.

[1] rust-lang/rfcs#1682

Also removed the unused `index` field.
In both Ruby and [Rust][1], it is considered idomatic to name the
getter after the name of the attribute.

Also cleaned up some whitespace inconsistency.

[1]: https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#gettersetter-apis
This seems idomatic in Ruby, and matches (no pun intended) how
`String#match`, `Regexp#match` and friends work.
@chancancode
Copy link
Author

By the way, I was going to suggest that you may want to implement a default match method for each *Matcher class (that returns the best Match or nil) so they can all duck-type for each other, and it also matches (again, no pun intended) how String, Regexp, etc work in Ruby. For bonus points, you can even alias them to === and =~.

While you cannot have a method called match in Rust (it's a reserved word), you can use the #[ruby_name = "..."] feature to rename it:

ruby! {
    class MyMatcher {
        #[ruby_name = "match"]
        def match_text(text: String, ...) { ... }
    }
}

In general, you can use can use this feature to define methods that has strange names in Ruby, like =~ (although you can only pick one – I opened tildeio/helix#131 to track the feature request).

I don't know enough about your API to know if it make sense though, so I will leave that one up to you.

@timgluz
Copy link
Contributor

timgluz commented Oct 17, 2017

Many thanks for your PR!

I will review your PR sometime soon, most likely on weekend;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants