From 9409ed6be5a0c43637daa2a3e66e699da83f4873 Mon Sep 17 00:00:00 2001 From: Ronan Rodrigo Nunes Date: Fri, 19 Sep 2014 15:29:43 -0300 Subject: [PATCH] A shortcut to BSON::ObjectId.from_string A shortcut to BSON::ObjectId.from_string('048fec556265664f5b110000') instead this, just use '048fec556265664f5b110000'.to_object_id --- lib/bson/string.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/bson/string.rb b/lib/bson/string.rb index e08b0267f..953b7f214 100644 --- a/lib/bson/string.rb +++ b/lib/bson/string.rb @@ -96,6 +96,13 @@ def to_bson_cstring(encoded = ''.force_encoding(BINARY)) def to_bson_object_id ObjectId.repair(self) end + + # A shortcut to BSON::ObjectId.from_string('048fec556265664f5b110000') + # @example Convert the string to an object id. + # '048fec556265664f5b110000'.to_object_id + def to_object_id + BSON::ObjectId.from_string(self) + end # Convert the string to a UTF-8 string then force to binary. This is so # we get errors for strings that are not UTF-8 encoded.