-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.12.1
-
Component/s: BSON
-
None
-
Minor Change
The function BSON::ObjectId() is currently a simple wrapper for BSON::ObjectId.from_string().
However, the signature of BSON::ObjectId() suggests that it is a conversion function. Conversion functions generally take different kinds of input and converts it do the desired type. They typically return the input if the input already is of the correct type.
BSON::ObjectId breaks this convention by throwing an error if the input is already an ObjectId.
Here's a general discussion on ruby conversion function idioms: http://devblog.avdi.org/2012/05/07/a-ruby-conversion-idiom/
I've implemented this here: https://github.com/jesjos/mongo-ruby-driver/commit/22c0cb838bf7ca6f7979ea4f334d3a11c481b8a6