If BSON::ObjectId(...) is given an existing object ID, it should return it without creating a new one

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Ruby Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      In app code it is fairly common to do something like;

       

      ids = ids_or_strings.map {|id| BSON::ObjectId(id) }
      

      This BSON::ObjectId(id) works even if given a BSON::ObjectId instead of a string, however, currently it needlessly instantiates a new BSON::ObjectId object:

      my_id1 = BSON::ObjectId.new
      
      my_id2 = BSON::ObjectId(my_id1)
      
      # Object#object_id are diffent, meaning they are different objects
      my_id1.object_id != my_id2.object_id # true

      It would be great if this method didn't perform this needless object allocation.

            Assignee:
            Dmitry Rybakov
            Reporter:
            Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: