Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
wonkey array first and last???
ruby-1.9.2-p290 :032 > a
=> [#<Review _id: BSON::ObjectId('4fa2d32c2e47cf1444000011'), allow_publish: true, business_id: BSON::ObjectId('4fa2d28a2e47cf143b00000c'), content: "Best adjustment ever!", rating: 5, status: "published", title: "You Rock", user_id: BSON::ObjectId('4fa2d32c2e47cf144400000f'), version: 2, versions: [#<Review::Version _id: BSON::ObjectId('4fa2d32c2e47cf1444000012'), modified: {"title"=>"You Rock", "rating"=>5, "content"=>"Best adjustment ever!", "allow_publish"=>true, "status"=>"pending", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2d32c2e47cf144400000f')}, version: 1>, #<Review::Version _id: BSON::ObjectId('4fa2df1c2e47cf12a70000a8'), modified: {"title"=>"You Rock", "rating"=>5, "content"=>"Best adjustment ever!", "allow_publish"=>true, "status"=>"published", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2d32c2e47cf144400000f')}, version: 2>]>, #<Review _id: BSON::ObjectId('4fa2e1282e47cf144400001e'), allow_publish: true, business_id: BSON::ObjectId('4fa2d28a2e47cf143b00000c'), content: "Worst adjustment ever!", rating: 1, status: "published", title: "You Suck", user_id: BSON::ObjectId('4fa2e1282e47cf144400001c'), version: 2, versions: [#<Review::Version _id: BSON::ObjectId('4fa2e1292e47cf144400001f'), modified: {"title"=>"You Suck", "rating"=>1, "content"=>"Worst adjustment ever!", "allow_publish"=>true, "status"=>"pending", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2e1282e47cf144400001c')}, version: 1>, #<Review::Version _id: BSON::ObjectId('4fa2e1352e47cf12a70000d4'), modified: {"title"=>"You Suck", "rating"=>1, "content"=>"Worst adjustment ever!", "allow_publish"=>true, "status"=>"published", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2e1282e47cf144400001c')}, version: 2>]>]
ruby-1.9.2-p290 :033 > a.first
=> #<Review _id: BSON::ObjectId('4fa2d32c2e47cf1444000011'), allow_publish: true, business_id: BSON::ObjectId('4fa2d28a2e47cf143b00000c'), content: "Best adjustment ever!", rating: 5, status: "published", title: "You Rock", user_id: BSON::ObjectId('4fa2d32c2e47cf144400000f'), version: 2, versions: [#<Review::Version _id: BSON::ObjectId('4fa2d32c2e47cf1444000012'), modified: {"title"=>"You Rock", "rating"=>5, "content"=>"Best adjustment ever!", "allow_publish"=>true, "status"=>"pending", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2d32c2e47cf144400000f')}, version: 1>, #<Review::Version _id: BSON::ObjectId('4fa2df1c2e47cf12a70000a8'), modified: {"title"=>"You Rock", "rating"=>5, "content"=>"Best adjustment ever!", "allow_publish"=>true, "status"=>"published", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2d32c2e47cf144400000f')}, version: 2>]>
ruby-1.9.2-p290 :034 > a.last
=> #<Review _id: BSON::ObjectId('4fa2d32c2e47cf1444000011'), allow_publish: true, business_id: BSON::ObjectId('4fa2d28a2e47cf143b00000c'), content: "Best adjustment ever!", rating: 5, status: "published", title: "You Rock", user_id: BSON::ObjectId('4fa2d32c2e47cf144400000f'), version: 2, versions: [#<Review::Version _id: BSON::ObjectId('4fa2d32c2e47cf1444000012'), modified: {"title"=>"You Rock", "rating"=>5, "content"=>"Best adjustment ever!", "allow_publish"=>true, "status"=>"pending", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2d32c2e47cf144400000f')}, version: 1>, #<Review::Version _id: BSON::ObjectId('4fa2df1c2e47cf12a70000a8'), modified: {"title"=>"You Rock", "rating"=>5, "content"=>"Best adjustment ever!", "allow_publish"=>true, "status"=>"published", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2d32c2e47cf144400000f')}, version: 2>]>
ruby-1.9.2-p290 :035 > a.first == a.last
=> true
ruby-1.9.2-p290 :044 > a[0] == a[1]
=> false
ruby-1.9.2-p290 :036 > a.count
=> 2
ruby-1.9.2-p290 :037 > a[0]
=> #<Review _id: BSON::ObjectId('4fa2d32c2e47cf1444000011'), allow_publish: true, business_id: BSON::ObjectId('4fa2d28a2e47cf143b00000c'), content: "Best adjustment ever!", rating: 5, status: "published", title: "You Rock", user_id: BSON::ObjectId('4fa2d32c2e47cf144400000f'), version: 2, versions: [#<Review::Version _id: BSON::ObjectId('4fa2d32c2e47cf1444000012'), modified: {"title"=>"You Rock", "rating"=>5, "content"=>"Best adjustment ever!", "allow_publish"=>true, "status"=>"pending", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2d32c2e47cf144400000f')}, version: 1>, #<Review::Version _id: BSON::ObjectId('4fa2df1c2e47cf12a70000a8'), modified: {"title"=>"You Rock", "rating"=>5, "content"=>"Best adjustment ever!", "allow_publish"=>true, "status"=>"published", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2d32c2e47cf144400000f')}, version: 2>]>
ruby-1.9.2-p290 :038 > a[1]
=> #<Review _id: BSON::ObjectId('4fa2e1282e47cf144400001e'), allow_publish: true, business_id: BSON::ObjectId('4fa2d28a2e47cf143b00000c'), content: "Worst adjustment ever!", rating: 1, status: "published", title: "You Suck", user_id: BSON::ObjectId('4fa2e1282e47cf144400001c'), version: 2, versions: [#<Review::Version _id: BSON::ObjectId('4fa2e1292e47cf144400001f'), modified: {"title"=>"You Suck", "rating"=>1, "content"=>"Worst adjustment ever!", "allow_publish"=>true, "status"=>"pending", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2e1282e47cf144400001c')}, version: 1>, #<Review::Version _id: BSON::ObjectId('4fa2e1352e47cf12a70000d4'), modified: {"title"=>"You Suck", "rating"=>1, "content"=>"Worst adjustment ever!", "allow_publish"=>true, "status"=>"published", "business_id"=>BSON::ObjectId('4fa2d28a2e47cf143b00000c'), "user_id"=>BSON::ObjectId('4fa2e1282e47cf144400001c')}, version: 2>]>
ruby-1.9.2-p290 :039 > b = ['first', 'last']
=> ["first", "last"]
ruby-1.9.2-p290 :040 > b.first
=> "first"
ruby-1.9.2-p290 :041 > b.last
=> "last"
ruby-1.9.2-p290 :042 > a.class
=> Array
ruby-1.9.2-p290 :043 > b.class
=> Array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment