diff --git a/lib/bson/types/object_id.rb b/lib/bson/types/object_id.rb index 6bfb7dc..afbc128 100644 --- a/lib/bson/types/object_id.rb +++ b/lib/bson/types/object_id.rb @@ -116,6 +116,13 @@ module BSON @data.dup end + # Returns the object id as a single element in an array for use with Kernel#Array + # + # @return [Array] + def to_ary + [ self ] + end + # Given a string representation of an ObjectId, return a new ObjectId # with that value. # diff --git a/test/bson/object_id_test.rb b/test/bson/object_id_test.rb index 837133e..78f93ea 100644 --- a/test/bson/object_id_test.rb +++ b/test/bson/object_id_test.rb @@ -135,4 +135,10 @@ class ObjectIdTest < Test::Unit::TestCase id = ObjectId.new assert_equal({"$oid" => id.to_s}, id.as_json) end + + def test_to_ary + id = ObjectId.new + assert_equal [id], id.to_ary + assert_equal Array(id), id.to_ary + end end