2.13.2 (latest) 2.13.1 2.12.3 2.11.1 2.10.2 2.9.1 2.8.0 2.7.1 2.6.5 Reference documentation and code samples for the Cloud Bigtable API class Google::Cloud::Bigtable::ColumnFamilyMap.

Represents a table's column families.


<br />

See [Project#create_table](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-Project.md.txt#Google__Cloud__Bigtable__Project_create_table_instance_ "Google::Cloud::Bigtable::Project#create_table (method)"), [Instance#create_table](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-Instance.md.txt#Google__Cloud__Bigtable__Instance_create_table_instance_ "Google::Cloud::Bigtable::Instance#create_table (method)") and
[Table#column_families](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-Table.md.txt#Google__Cloud__Bigtable__Table_column_families_instance_ "Google::Cloud::Bigtable::Table#column_families (method)").

## Inherits

- Object

## Includes

- Enumerable

## Examples

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

column_families = Google::Cloud::Bigtable::ColumnFamilyMap.new

column_families.add "cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
column_families.add "cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
```

Create a table with a block yielding a ColumnFamilyMap.

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table "my-instance", "my-table" do |cfm|
  cfm.add "cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
  cfm.add "cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)

  gc_rule = Google::Cloud::Bigtable::GcRule.union(
    Google::Cloud::Bigtable::GcRule.max_age(1800),
    Google::Cloud::Bigtable::GcRule.max_versions(3)
  )
  cfm.add "cf3", gc_rule: gc_rule
end

puts table.column_families
```

Update column families with a block yielding a ColumnFamilyMap.

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table "my-instance", "my-table", perform_lookup: true

table.column_families do |cfm|
  cfm.add "cf4", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
  cfm.add "cf5", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)

  rule_1 = Google::Cloud::Bigtable::GcRule.max_versions 3
  rule_2 = Google::Cloud::Bigtable::GcRule.max_age 600
  rule_union = Google::Cloud::Bigtable::GcRule.union rule_1, rule_2
  cfm.update "cf2", gc_rule: rule_union

  cfm.delete "cf3"
end

puts table.column_families["cf3"] #=> nil
```

## Methods

### #\[\]

```ruby
def [](name) -> ColumnFamily
```
Retrieves the ColumnFamily object corresponding to the `name`. If not
found, returns `nil`.
**Returns**

- ([ColumnFamily](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamily.md.txt))

### #add

```ruby
def add(name, gc_rule: nil)
```
**Aliases**

- [#create](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_create_instance_)
Adds a new column family to the table.
**Overloads**

```ruby
def add(name, gc_rule: nil)
```
Adds a new column family to the table. **Parameters**

- **name** (String) --- Column family name.
- **gc_rule** ([Google::Cloud::Bigtable::GcRule](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-GcRule.md.txt)) *(defaults to: nil)* --- The garbage collection rule to be used for the column family. Optional. The service default value will be used when not specified.
**Raises**

- (ArgumentError) --- if the column family name already exists.
- (FrozenError) --- if the column family map is frozen.
**Example**

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table "my-instance", "my-table", perform_lookup: true

table.column_families do |column_families|
  column_families.add "cf4", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
  column_families.add "cf5", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
end
```

### #create

```ruby
def add(name, gc_rule: nil)
```
**Alias Of** : [#add](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_add_instance_) Adds a new column family to the table.
**Overloads**

```ruby
def add(name, gc_rule: nil)
```
Adds a new column family to the table. **Parameters**

- **name** (String) --- Column family name.
- **gc_rule** ([Google::Cloud::Bigtable::GcRule](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-GcRule.md.txt)) *(defaults to: nil)* --- The garbage collection rule to be used for the column family. Optional. The service default value will be used when not specified.
**Raises**

- (ArgumentError) --- if the column family name already exists.
- (FrozenError) --- if the column family map is frozen.
**Example**

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table "my-instance", "my-table", perform_lookup: true

table.column_families do |column_families|
  column_families.add "cf4", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
  column_families.add "cf5", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
end
```

### #delete

```ruby
def delete(name)
```
**Aliases**

- [#drop](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_drop_instance_)
Deletes the named column family from the table.
**Parameter**

- **name** (String) --- Column family name.
**Raises**

- (ArgumentError) --- if the column family name does not exist.
- (FrozenError) --- if the column family map is frozen.
**Example**

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table "my-instance", "my-table", perform_lookup: true

table.column_families do |column_families|
  column_families.delete "cf3"
end
```

### #drop

```ruby
def drop(name)
```
**Alias Of** : [#delete](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_delete_instance_) Deletes the named column family from the table.
**Parameter**

- **name** (String) --- Column family name.
**Raises**

- (ArgumentError) --- if the column family name does not exist.
- (FrozenError) --- if the column family map is frozen.
**Example**

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table "my-instance", "my-table", perform_lookup: true

table.column_families do |column_families|
  column_families.delete "cf3"
end
```

### #each

```ruby
def each() { |name, column_family| ... } -> Enumerator, nil
```
Calls the block once for each column family in the map, passing
the name and column family pair as parameters.


<br />

If no block is given, an enumerator is returned instead.
**Yields**

- (name, column_family) --- The name and column family pair.
**Yield Parameters**

- **name** (String) --- the column family name.
- **column_family** ([ColumnFamily](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamily.md.txt)) --- the column family object.
**Returns**

- (Enumerator, nil) --- An enumerator is returned if no block is given, otherwise `nil`.

### #empty?

```ruby
def empty?() -> Boolean
```
Returns true if the map contains no name and column family pairs.
**Returns**

- (Boolean)

### #initialize

```ruby
def initialize() { |_self| ... } -> ColumnFamilyMap
```
Creates a new ColumnFamilyMap object.
**Yields**

- (_self)
**Yield Parameter**

- **_self** ([Google::Cloud::Bigtable::ColumnFamilyMap](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt)) --- the object that the method was called on
**Returns**

- ([ColumnFamilyMap](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt)) --- a new instance of ColumnFamilyMap
**Examples**

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

column_families = Google::Cloud::Bigtable::ColumnFamilyMap.new

column_families.add "cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
column_families.add "cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
```

Create new column families using block syntax:

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

column_families = Google::Cloud::Bigtable::ColumnFamilyMap.new do |cfm|
  cfm.add "cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
  cfm.add "cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
end
```

### #key?

```ruby
def key?(name) -> Boolean
```
**Alias Of** : [#name?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_name?_instance_) Returns true if the given name is present in the map.
**Returns**

- (Boolean)

### #keys

```ruby
def keys() -> Array<String>
```
**Alias Of** : [#names](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_names_instance_) Returns a new array populated with the names from the map.
**Returns**

- (Array\<String\>)

### #length

```ruby
def length() -> Integer
```
**Aliases**

- [#size](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_size_instance_)
Returns the number of name and column family pairs in the map.
**Returns**

- (Integer)

### #name?

```ruby
def name?(name) -> Boolean
```
**Aliases**

- [#key?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_key?_instance_)
Returns true if the given name is present in the map.
**Returns**

- (Boolean)

### #names

```ruby
def names() -> Array<String>
```
**Aliases**

- [#keys](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_keys_instance_)
Returns a new array populated with the names from the map.
**Returns**

- (Array\<String\>)

### #size

```ruby
def size() -> Integer
```
**Alias Of** : [#length](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.md.txt#Google__Cloud__Bigtable__ColumnFamilyMap_length_instance_) Returns the number of name and column family pairs in the map.
**Returns**

- (Integer)

### #update

```ruby
def update(name, gc_rule: nil)
```
Updates an existing column family in the table.
**Parameters**

- **name** (String) --- Column family name.
- **gc_rule** ([Google::Cloud::Bigtable::GcRule](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-GcRule.md.txt)) *(defaults to: nil)* --- The new garbage collection rule to be used for the column family. Optional. The service default value will be used when not specified.
**Raises**

- (ArgumentError) --- if the column family name does not exist.
- (FrozenError) --- if the column family map is frozen.
**Example**

```ruby
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table "my-instance", "my-table", perform_lookup: true

table.column_families do |column_families|
  rule_1 = Google::Cloud::Bigtable::GcRule.max_versions 3
  rule_2 = Google::Cloud::Bigtable::GcRule.max_age 600
  rule_union = Google::Cloud::Bigtable::GcRule.union rule_1, rule_2

  column_families.update "cf2", gc_rule: rule_union
end
```