Reference documentation and code samples for the Cloud Spanner API class Google::Cloud::Spanner::Range.
Range
Represents a range of rows in a table or index. A range has a start key
and an end key. These keys can be open or closed, indicating if the
range includes rows with that key.
[[["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 Spanner API - Class Google::Cloud::Spanner::Range (v2.27.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.27.0 (latest)](/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Range)\n- [2.26.0](/ruby/docs/reference/google-cloud-spanner/2.26.0/Google-Cloud-Spanner-Range)\n- [2.25.0](/ruby/docs/reference/google-cloud-spanner/2.25.0/Google-Cloud-Spanner-Range)\n- [2.24.0](/ruby/docs/reference/google-cloud-spanner/2.24.0/Google-Cloud-Spanner-Range)\n- [2.23.0](/ruby/docs/reference/google-cloud-spanner/2.23.0/Google-Cloud-Spanner-Range)\n- [2.22.0](/ruby/docs/reference/google-cloud-spanner/2.22.0/Google-Cloud-Spanner-Range)\n- [2.21.0](/ruby/docs/reference/google-cloud-spanner/2.21.0/Google-Cloud-Spanner-Range)\n- [2.20.0](/ruby/docs/reference/google-cloud-spanner/2.20.0/Google-Cloud-Spanner-Range)\n- [2.19.1](/ruby/docs/reference/google-cloud-spanner/2.19.1/Google-Cloud-Spanner-Range)\n- [2.18.1](/ruby/docs/reference/google-cloud-spanner/2.18.1/Google-Cloud-Spanner-Range)\n- [2.17.0](/ruby/docs/reference/google-cloud-spanner/2.17.0/Google-Cloud-Spanner-Range)\n- [2.16.1](/ruby/docs/reference/google-cloud-spanner/2.16.1/Google-Cloud-Spanner-Range)\n- [2.15.0](/ruby/docs/reference/google-cloud-spanner/2.15.0/Google-Cloud-Spanner-Range)\n- [2.14.0](/ruby/docs/reference/google-cloud-spanner/2.14.0/Google-Cloud-Spanner-Range)\n- [2.13.0](/ruby/docs/reference/google-cloud-spanner/2.13.0/Google-Cloud-Spanner-Range)\n- [2.12.1](/ruby/docs/reference/google-cloud-spanner/2.12.1/Google-Cloud-Spanner-Range)\n- [2.11.0](/ruby/docs/reference/google-cloud-spanner/2.11.0/Google-Cloud-Spanner-Range) \nReference documentation and code samples for the Cloud Spanner API class Google::Cloud::Spanner::Range.\n\nRange\n-----\n\nRepresents a range of rows in a table or index. A range has a start key\nand an end key. These keys can be open or closed, indicating if the\nrange includes rows with that key. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/spanner\"\n\nspanner = Google::Cloud::Spanner.new\n\ndb = spanner.client \"my-instance\", \"my-database\"\n\nkey_range = db.range 1, 100\nresults = db.read \"users\", [:id, :name], keys: key_range\n\nresults.rows.each do |row|\n puts \"User #{row[:id]} is #{row[:name]}\"\nend\n```\n\nMethods\n-------\n\n### #begin\n\n def begin()\n\nReturns the object that defines the beginning of the range.\n\n### #end\n\n def end()\n\nReturns the object that defines the end of the range.\n\n### #exclude_begin?\n\n def exclude_begin?() -\u003e Boolean\n\nReturns `true` if the range excludes its beginning value. \n**Returns**\n\n- (Boolean)\n\n### #exclude_end?\n\n def exclude_end?() -\u003e Boolean\n\nReturns `true` if the range excludes its end value. \n**Returns**\n\n- (Boolean)\n\n### #initialize\n\n def initialize(beginning, ending, exclude_begin: false, exclude_end: false) -\u003e Range\n\nCreates a Spanner Range. This can be used in place of a Ruby Range\nwhen needing to exclude the beginning value. \n**Parameters**\n\n- **beginning** (Object) --- The object that defines the beginning of the range.\n- **ending** (Object) --- The object that defines the end of the range.\n- **exclude_begin** (Boolean) *(defaults to: false)* --- Determines if the range excludes its beginning value. Default is `false`.\n- **exclude_end** (Boolean) *(defaults to: false)* --- Determines if the range excludes its ending value. Default is `false`. \n**Returns**\n\n- ([Range](./Google-Cloud-Spanner-Range)) --- a new instance of Range\n**Example** \n\n```ruby\nrequire \"google/cloud/spanner\"\n\nspanner = Google::Cloud::Spanner.new\n\ndb = spanner.client \"my-instance\", \"my-database\"\n\nkey_range = Google::Cloud::Spanner::Range.new 1, 100\nresults = db.read \"users\", [:id, :name], keys: key_range\n\nresults.rows.each do |row|\n puts \"User #{row[:id]} is #{row[:name]}\"\nend\n```"]]