Reference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::Policy::Bindings.
Bindings
Enumerable object for managing Cloud IAM bindings associated with
a bucket.
Inherits
Object
Includes
Enumerable
Example
Updating a Policy from version 1 to version 3:
require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucket"my-bucket"bucket.uniform_bucket_level_access=truebucket.policyrequested_policy_version:3do|p|p.version# the value is 1p.version=3# Must be explicitly set to opt-in to support for conditions.expr="resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"p.bindings.insert({role:"roles/storage.admin",members:["user:owner@example.com"],condition:{title:"my-condition",description:"description of condition",expression:expr}})end
Methods
#each
defeach(){|binding|...}->Enumerator
Calls the block once for each binding in the collection, passing
a Binding object as parameter. A
Binding object is passed even
when the arguments to #insert were hash objects.
If no block is given, an enumerator is returned instead.
Yields
(binding) — A binding in this bindings collection.
Adds a binding or bindings to the collection. The arguments may be
Binding objects or equivalent hash
objects that will be implicitly coerced to binding objects.
Parameter
bindings (Google::Cloud::Storage::Policy::Binding, Hash) — One
or more bindings to be added to the policy owning the collection.
The arguments may be Binding
objects or equivalent hash objects that will be implicitly coerced
to binding objects.
require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucket"my-bucket"bucket.uniform_bucket_level_access=truebucket.policyrequested_policy_version:3do|p|p.version# the value is 1p.version=3# Must be explicitly set to opt-in to support for conditions.expr="resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"p.bindings.insert({role:"roles/storage.admin",members:["user:owner@example.com"],condition:{title:"my-condition",description:"description of condition",expression:expr}})end
#remove
defremove(*bindings)->Bindings
Deletes the binding or bindings from the collection that are equal to
the arguments. The specification arguments may be
Binding objects or equivalent hash
objects that will be implicitly coerced to binding objects.
Parameter
bindings (Google::Cloud::Storage::Policy::Binding, Hash) — One
or more specifications for bindings to be removed from the
collection. The arguments may be
Binding objects or equivalent
hash objects that will be implicitly coerced to binding objects.
require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucket"my-bucket"bucket.policyrequested_policy_version:3do|p|expr="resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"p.bindings.remove({role:"roles/storage.admin",members:["user:owner@example.com"],condition:{title:"my-condition",description:"description of condition",expression:expr}})end
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Storage API - Class Google::Cloud::Storage::Policy::Bindings (v1.57.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.57.0 (latest)](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings)\n- [1.56.0](/ruby/docs/reference/google-cloud-storage/1.56.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.55.0](/ruby/docs/reference/google-cloud-storage/1.55.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.54.0](/ruby/docs/reference/google-cloud-storage/1.54.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.53.0](/ruby/docs/reference/google-cloud-storage/1.53.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.52.0](/ruby/docs/reference/google-cloud-storage/1.52.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.51.0](/ruby/docs/reference/google-cloud-storage/1.51.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.50.0](/ruby/docs/reference/google-cloud-storage/1.50.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.49.0](/ruby/docs/reference/google-cloud-storage/1.49.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.48.1](/ruby/docs/reference/google-cloud-storage/1.48.1/Google-Cloud-Storage-Policy-Bindings)\n- [1.47.0](/ruby/docs/reference/google-cloud-storage/1.47.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.46.0](/ruby/docs/reference/google-cloud-storage/1.46.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.45.0](/ruby/docs/reference/google-cloud-storage/1.45.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.44.0](/ruby/docs/reference/google-cloud-storage/1.44.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.43.0](/ruby/docs/reference/google-cloud-storage/1.43.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.42.0](/ruby/docs/reference/google-cloud-storage/1.42.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.41.0](/ruby/docs/reference/google-cloud-storage/1.41.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.40.0](/ruby/docs/reference/google-cloud-storage/1.40.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.39.0](/ruby/docs/reference/google-cloud-storage/1.39.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.38.0](/ruby/docs/reference/google-cloud-storage/1.38.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.37.0](/ruby/docs/reference/google-cloud-storage/1.37.0/Google-Cloud-Storage-Policy-Bindings)\n- [1.36.2](/ruby/docs/reference/google-cloud-storage/1.36.2/Google-Cloud-Storage-Policy-Bindings)\n- [1.35.0](/ruby/docs/reference/google-cloud-storage/1.35.0/Google-Cloud-Storage-Policy-Bindings) \nReference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::Policy::Bindings.\n\nBindings\n--------\n\nEnumerable object for managing Cloud IAM bindings associated with\na bucket. \n\nInherits\n--------\n\n- Object \n\nIncludes\n--------\n\n- Enumerable\n\nExample\n-------\n\nUpdating a Policy from version 1 to version 3: \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\nbucket.uniform_bucket_level_access = true\n\nbucket.policy requested_policy_version: 3 do |p|\n p.version # the value is 1\n p.version = 3 # Must be explicitly set to opt-in to support for conditions.\n\n expr = \"resource.name.startsWith(\\\"projects/_/buckets/bucket-name/objects/prefix-a-\\\")\"\n p.bindings.insert({\n role: \"roles/storage.admin\",\n members: [\"user:owner@example.com\"],\n condition: {\n title: \"my-condition\",\n description: \"description of condition\",\n expression: expr\n }\n })\nend\n```\n\nMethods\n-------\n\n### #each\n\n def each() { |binding| ... } -\u003e Enumerator\n\nCalls the block once for each binding in the collection, passing\na [Binding](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding \"Google::Cloud::Storage::Policy::Binding (class)\") object as parameter. A\n[Binding](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding \"Google::Cloud::Storage::Policy::Binding (class)\") object is passed even\nwhen the arguments to [#insert](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings#Google__Cloud__Storage__Policy__Bindings_insert_instance_ \"Google::Cloud::Storage::Policy::Bindings#insert (method)\") were hash objects.\n\n\n\u003cbr /\u003e\n\nIf no block is given, an enumerator is returned instead. \n**Yields**\n\n- (binding) --- A binding in this bindings collection. \n**Yield Parameter**\n\n- **binding** ([Google::Cloud::Storage::Policy::Binding](./Google-Cloud-Storage-Policy-Binding)) --- A binding object, even when the arguments to [#insert](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings#Google__Cloud__Storage__Policy__Bindings_insert_instance_ \"Google::Cloud::Storage::Policy::Bindings#insert (method)\") were hash objects. \n**Returns**\n\n- (Enumerator)\n**Example** \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\npolicy = bucket.policy requested_policy_version: 3\npolicy.bindings.each do |binding|\n puts binding.role\nend\n```\n\n### #insert\n\n def insert(*bindings) -\u003e Bindings\n\nAdds a binding or bindings to the collection. The arguments may be\n[Binding](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding \"Google::Cloud::Storage::Policy::Binding (class)\") objects or equivalent hash\nobjects that will be implicitly coerced to binding objects. \n**Parameter**\n\n- **bindings** ([Google::Cloud::Storage::Policy::Binding](./Google-Cloud-Storage-Policy-Binding), Hash) --- One or more bindings to be added to the policy owning the collection. The arguments may be [Binding](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding \"Google::Cloud::Storage::Policy::Binding (class)\") objects or equivalent hash objects that will be implicitly coerced to binding objects. \n**Returns**\n\n- ([Bindings](./Google-Cloud-Storage-Policy-Bindings)) --- `self` for chaining.\n**Example**\n\nUpdating a Policy from version 1 to version 3: \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\nbucket.uniform_bucket_level_access = true\n\nbucket.policy requested_policy_version: 3 do |p|\n p.version # the value is 1\n p.version = 3 # Must be explicitly set to opt-in to support for conditions.\n\n expr = \"resource.name.startsWith(\\\"projects/_/buckets/bucket-name/objects/prefix-a-\\\")\"\n p.bindings.insert({\n role: \"roles/storage.admin\",\n members: [\"user:owner@example.com\"],\n condition: {\n title: \"my-condition\",\n description: \"description of condition\",\n expression: expr\n }\n })\nend\n```\n\n### #remove\n\n def remove(*bindings) -\u003e Bindings\n\nDeletes the binding or bindings from the collection that are equal to\nthe arguments. The specification arguments may be\n[Binding](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding \"Google::Cloud::Storage::Policy::Binding (class)\") objects or equivalent hash\nobjects that will be implicitly coerced to binding objects. \n**Parameter**\n\n- **bindings** ([Google::Cloud::Storage::Policy::Binding](./Google-Cloud-Storage-Policy-Binding), Hash) --- One or more specifications for bindings to be removed from the collection. The arguments may be [Binding](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding \"Google::Cloud::Storage::Policy::Binding (class)\") objects or equivalent hash objects that will be implicitly coerced to binding objects. \n**Returns**\n\n- ([Bindings](./Google-Cloud-Storage-Policy-Bindings)) --- `self` for chaining.\n**Example** \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\nbucket.policy requested_policy_version: 3 do |p|\n expr = \"resource.name.startsWith(\\\"projects/_/buckets/bucket-name/objects/prefix-a-\\\")\"\n p.bindings.remove({\n role: \"roles/storage.admin\",\n members: [\"user:owner@example.com\"],\n condition: {\n title: \"my-condition\",\n description: \"description of condition\",\n expression: expr\n }\n })\nend\n```"]]