Class Hashie::Dash
In: lib/hashie/dash.rb
Parent: Hashie::Hash

A Dash is a ‘defined’ or ‘discrete’ Hash, that is, a Hash that has a set of defined keys that are accessible (with optional defaults) and only those keys may be set or read.

Dashes are useful when you need to create a very simple lightweight data object that needs even fewer options and resources than something like a DataMapper resource.

It is preferrable to a Struct because of the in-class API for defining properties as well as per-property defaults.

Methods

[]   []=   inherited   new   property   property?   required?  

Included Modules

Hashie::PrettyInspect

External Aliases

inspect -> to_s
[] -> _regular_reader
_regular_writer -> :

Attributes

defaults  [R] 
properties  [R] 
required_properties  [R] 

Public Class methods

You may initialize a Dash with an attributes hash just like you would many other kinds of data objects.

Defines a property on the Dash. Options are as follows:

  • :default - Specify a default value for this property, to be returned before a value is set on the property in a new Dash.
  • :required - Specify the value as required for this property, to raise an error if a value is unset in a new or existing Dash.

Check to see if the specified property has already been defined.

Check to see if the specified property is required.

Public Instance methods

Retrieve a value from the Dash (will return the property‘s default value if it hasn‘t been set).

Set a value on the Dash in a Hash-like way. Only works on pre-existing properties.

[Validate]