Added BSON::ObjectId#to_ary

This commit is contained in:
Farrel Lifson 2012-05-26 01:16:11 +02:00
parent 5591e3dfe3
commit 078354a39a
2 changed files with 13 additions and 0 deletions

View File

@ -116,6 +116,13 @@ module BSON
@data.dup @data.dup
end 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 # Given a string representation of an ObjectId, return a new ObjectId
# with that value. # with that value.
# #

View File

@ -135,4 +135,10 @@ class ObjectIdTest < Test::Unit::TestCase
id = ObjectId.new id = ObjectId.new
assert_equal({"$oid" => id.to_s}, id.as_json) assert_equal({"$oid" => id.to_s}, id.as_json)
end end
def test_to_ary
id = ObjectId.new
assert_equal [id], id.to_ary
assert_equal Array(id), id.to_ary
end
end end