Project

omnistruct

0.0
No commit activity in last 3 years
No release in over 3 years
OmniStruct: Struct Utilities -- Helpers for ClassyStruct, OpenStruct and Struct
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 5.4.3, ~> 5.4

Runtime

>= 0.3.2, ~> 0.3
 Project Readme

OmniStruct - Build Status

Helpers for using ClassyStruct, OpenStruct and/or Struct over Hash

Usage

Require after or in place of classy_struct, ostruct and/or struct.

# good
require 'omnistruct`

# also good
require 'ostruct`
require 'omnistruct`

# bad
require 'omnistruct`
require 'ostruct`

TODO: document the following better

Add's the following methods to Hash;

# Hash
##

# class methods
Hash.struct_type
Hash.struct_type=

# instance methods
Hash.new.to_struct(type=Hash.struct_type)

Add's the following common Hash methods to struct types;

# All: ClassyStruct / OpenStruct / Struct
##

struct = <struct type>.to_struct( [type] )
merged = <struct type>.merge( Hash.new | <struct type> )
json   = <struct type>.to_json
value  = <struct type>.delete(:key)

# ClassyStruct
locked = <classy struct>.lock
locked.class
# => "Struct"

# OpenStruct
OpenStruct.new.merge!( Hash.new | <struct type> )

locked = OpenStruct.new.lock
locked.class
# => "Struct"

# Struct
unlocked = <Struct>.unlock( [type] )

Development

bundle install --path .bundle
bundle exec ruby ./test.rb