Class: Data

Inherits:
Object
  • Object
show all
Includes:
Everythingrb::InspectQuotable
Defined in:
lib/everythingrb/data.rb

Overview

Extensions to Ruby’s core Data class

Provides:

  • #to_deep_h: Recursively convert to hash with all nested objects

  • #in_quotes, #with_quotes: Wrap object in quotes

Instance Method Summary collapse

Methods included from Everythingrb::InspectQuotable

#in_quotes

Instance Method Details

#to_deep_hHash

Recursively converts the Data object and all nested objects to hashes

This method traverses the entire Data structure, converting not just the top-level Data object but also nested Data objects, Structs, OpenStructs, and any other objects that implement ‘to_h`.

Examples:

Person = Data.define(:name, :profile)
person = Person.new(name: "Alice", profile: {roles: ["admin"]})
person.to_deep_h  # => {name: "Alice", profile: {roles: ["admin"]}}

Returns:

  • (Hash)

    A deeply converted hash of the Data object



27
28
29
# File 'lib/everythingrb/data.rb', line 27

def to_deep_h
  to_h.to_deep_h
end