Class: Layout::Dictionary

Inherits:
Object
  • Object
show all
Includes:
Enumerable

Overview

This is the interface to a LayOut dictionary. A Dictionary wraps key/value pairs.

Examples:

dict = Layout::Dictionary.new

Version:

  • LayOut 2026.0

Instance Method Summary # collapse

Constructor Details

#initializeLayout::Dictionary #initialize(dict) ⇒ Layout::Dictionary

The #initialize method creates a new Layout::Dictionary.

Examples:

doc = Layout::Dictionary.new
doc2 = Layout::Dictionary.new({"String key" => "string value", "Number key" => 42})

Overloads:

Raises:

  • (ArgumentError)

    if dict isn't a dictionary or hash

Version:

  • LayOut 2026.0

Instance Method Details

#[](key) ⇒ String, ...

The #[] method retrieves the value for a given key.

Examples:

dictionary = Layout::Dictionary.new
dictionary['test'] = 115

# value will contain 115
value = dictionary["test"]

Parameters:

  • key (String)

    The name of the attribute.

Returns:

Version:

  • LayOut 2026.0

#[]=(key, value) ⇒ Object

The #[]= method sets a value for a given key.

Creates a new dictionary entry for the given key if needed.

Examples:

dictionary = Layout::Dictionary.new
dictionary['test'] = 110
value = dictionary['test2'] = 120
p value

Parameters:

Version:

  • LayOut 2026.0

#delete_key(key) ⇒ String, ...

The #delete_key method deletes a key/value pair from the dictionary.

Examples:

dictionary = Layout::Dictionary.new
dictionary["attr_one"] = "one"
dictionary["attr_two"] = "two"

# Delete a key/value pair and get the deleted value.
value = dictionary.delete_key("attr_one")

Parameters:

  • key (String)

    The key to be deleted.

Returns:

Version:

  • LayOut 2026.0

#each {|key, value| ... } ⇒ Object

The #each_pair method is an alias for #each.

Examples:

dictionary = Layout::Dictionary.new
dictionary["attr_one"] = "one"
dictionary["attr_two"] = "two"

# iterates through all attributes and prints the key to the screen
dictionary.each_pair { | key, value |
  puts "#{key} = #{value}"
}

Yields:

  • (key, value)

Yield Parameters:

See Also:

Version:

  • LayOut 2026.0

#each_key {|key| ... } ⇒ Object

The #each_key method iterates through all of the dictionary keys.

Examples:

dictionary = Layout::Dictionary.new
dictionary["attr_one"] = "one"
dictionary["attr_two"] = "two"

# iterates through all attributes and prints the key to the screen
dictionary.each_key { |key| puts key }

Yield Parameters:

Version:

  • LayOut 2026.0

#each_pair {|key, value| ... } ⇒ Object

The #each_pair method is an alias for #each.

Examples:

dictionary = Layout::Dictionary.new
dictionary["attr_one"] = "one"
dictionary["attr_two"] = "two"

# iterates through all attributes and prints the key to the screen
dictionary.each_pair { | key, value |
  puts "#{key} = #{value}"
}

Yields:

  • (key, value)

Yield Parameters:

See Also:

Version:

  • LayOut 2026.0

#empty?Boolean

The #empty? method checks if the dictionary is empty.

Examples:

dictionary = Layout::Dictionary.new
dictionary["attribute_one"] = "1"
dictionary.empty? # Returns false

Returns:

  • (Boolean)

Version:

  • LayOut 2026.0

#keysArray<String>

The #keys method retrieves an array with all of the dictionary keys.

Examples:

dictionary = Layout::Dictionary.new
dictionary["attr_one"] = "one"
dictionary["attr_two"] = "two"

# Gets an array of keys
keys = dictionary.keys

Returns:

  • (Array<String>)

    an array of keys within the dictionary if successful

Version:

  • LayOut 2026.0

#lengthInteger

The #length method retrieves the size (number of elements) of a dictionary.

Examples:

dictionary = Layout::Dictionary.new
dictionary['Hello'] = 'World'
number = dictionary.length

Returns:

  • (Integer)

See Also:

Version:

  • LayOut 2026.0

#sizeInteger

The #length method retrieves the size (number of elements) of a dictionary.

Examples:

dictionary = Layout::Dictionary.new
dictionary['Hello'] = 'World'
number = dictionary.length

Returns:

  • (Integer)

See Also:

Version:

  • LayOut 2026.0

#valuesArray<Object>

The #values method retrieves an array with all of the dictionary values.

Examples:

dictionary = Layout::Dictionary.new
dictionary["attr_one"] = "one"
dictionary["attr_two"] = "two"

# Gets an array of values
values = dictionary.values

Returns:

  • (Array<Object>)

    an array of values within the dictionary if successful

Version:

  • LayOut 2026.0