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

add match with block method to string. Fixes incorrect usage in docs #3606

Closed
wants to merge 1 commit into from
Closed

Conversation

jwoertink
Copy link
Contributor

In the docs for MatchData it mentions an example using a block:

"Crystal".match(/[p-s]/) do |md|
  md.string # => "Crystal"
  md[0]     # => "r"
  md[1]?    # => nil
end

This example doesn't work in master as it throws 'String#match' is not expected to be invoked with a block, but a block was given. This PR adds this block method in.

One thing I do have a question about is in the docs it says md.string, but running the code like that will throw a undefined method 'string' for Nil compile-time error. Adding not_nil! makes it work, but it feels weird to always have to add that in. Should this block just yield match.not_nil!? or should I also add in an update to the docs to show that usage?

@RX14
Copy link
Member

RX14 commented Nov 29, 2016

It should yield match if match

@asterite
Copy link
Member

This was removed here. We need to update the docs for MatchData.

@asterite asterite closed this Nov 29, 2016
@asterite
Copy link
Member

(I'll do it soon, don't worry)

asterite pushed a commit that referenced this pull request Nov 30, 2016
firejox pushed a commit to firejox/crystal that referenced this pull request Dec 12, 2016
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