Permalink
Browse files

Add #first

  • Loading branch information...
1 parent 95340ce commit 19b70838d4fd2ecda7eca1f8a34adf27a9da1d0d @drbrain committed Mar 28, 2011
Showing with 28 additions and 0 deletions.
  1. +12 −0 lib/pasteboard.rb
  2. +16 −0 test/test_pasteboard.rb
View
12 lib/pasteboard.rb
@@ -102,6 +102,18 @@ def each flavor = nil # :yields: item
end
##
+ # Retrieves the first item in the pasteboard.
+ #
+ # If +flavor+ is given only the given flavor's data is returned. If no
+ # flavor matches nil is returned.
+ #
+ # See #[] for a description of an item.
+
+ def first flavor = nil
+ self[0, flavor]
+ end
+
+ ##
# Returns the item with +id+ in the pasteboard.
#
# If +flavor+ is given only the given flavor's data is returned. If no
View
16 test/test_pasteboard.rb
@@ -62,6 +62,22 @@ def test_copy_item_flavor_data
assert_equal Encoding::UTF_8, data.encoding if @encoding
end
+ def test_first
+ util_put
+
+ item = @pb.first
+
+ assert_equal @item, item[0, 2]
+ end
+
+ def test_first_flavor
+ util_put
+
+ item = @pb.first Pasteboard::Type::UTF_8
+
+ assert_equal 'π', item
+ end
+
def test_get
util_put

0 comments on commit 19b7083

Please sign in to comment.