From 078354a39a985d84e8597425535f7b6b3c3fdfcf Mon Sep 17 00:00:00 2001 From: Farrel Lifson Date: Sat, 26 May 2012 01:16:11 +0200 Subject: [PATCH] Added BSON::ObjectId#to_ary --- lib/bson/types/object_id.rb | 7 +++++++ test/bson/object_id_test.rb | 6 ++++++ 2 files changed, 13 insertions(+) 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