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

ruby: return nil for out of bounds #332

Merged
merged 1 commit into from
May 3, 2015

Conversation

skippy
Copy link
Contributor

@skippy skippy commented May 1, 2015

ruby returns nil if an array index is out of bounds

also allows negative indicies (again, to make it act more like a ruby lib)

if (index < 0 && repeated_field->size > 0) {
index = repeated_field->size + index;
}
return index;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not add this to the header file; it has been awhile but if I remember correctly header files are really for methods you want exposed vs internal-use-only methods.

anyway, let me know if there are any issues here, including styling and naming conventions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, file-internal helpers don't need to go in the header. Probably good to add a static though (this keeps the symbol internal to the file, like an anonymous namespace in C++).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@skippy skippy changed the title ruby: Nil for out of bounds ruby: return nil for out of bounds May 1, 2015

$ gem install bundler
$ bundle

Then install the required Ruby gems (JRuby):

$ jgem install bundler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is jgem necessary even when using rvm? IIRC, I had managed to just gem install bundler while in an environment that had selected JRuby via rvm, but it's been a while.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right; jgem is no longer needed. I'll remove (running gem was hanging, but there was a stuck thread; I reran and it worked fine)

ruby arrays don't throw an exception; they return nil.  Lets do the
same!

this fix also includes the ability to use negative array indicies
#make sure we set the RepeatedField and can add to it
m = TestMessage.new
assert m.repeated_string == []
m.repeated_string << 'ok'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was not working in master; see comment in RubyMessage.

@cfallin
Copy link
Contributor

cfallin commented May 3, 2015

OK, this looks good; I'll go ahead and merge. Thanks!

cfallin added a commit that referenced this pull request May 3, 2015
ruby: return nil for out of bounds
@cfallin cfallin merged commit dcf1213 into protocolbuffers:master May 3, 2015
@skippy skippy deleted the nil-out-of-bounds branch May 3, 2015 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants