Class Hashie::Dash
In: lib/hashie/dash.rb
Parent: 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

Included Modules

Hashie::Extensions::PrettyInspect

External Aliases

inspect -> to_s

Attributes

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

Public Class methods

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. If a Proc is provided, it will be run in the context of the Dash instance. If a Symbol is provided, the property it represents must not be nil. The property is only required if the value is truthy.
  • :message - Specify custom error message for required property

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

Check to see if the specified property is required.

[Validate]