0.0
No commit activity in last 3 years
No release in over 3 years
A Hash to object converter
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
 Project Readme

A Hash to object converter¶ ↑

Allows you to convert complex Hashes into objects for more common use.

In your Gemfile, make sure you have this gem:

gem 'phantom-object'

Now you can do this

h = {
  key: "Some value",
  another_key: "Another value"
}

o = PhantomObject.new(h)

p o.key
# => "Some value"
p o.another_key
# => "Another value"

And even this

h = {
  nested: {
    key: "Some value"
  }
}

o = PhantomObject.new(h)

p o.nested.key
# => "Some value"

For any level, and with arrays

And also you can do this, instead of PhantomObject.new()

h = {
  key: "Some value",
  another_key: "Another value"
}

o = h.to_object

p o.key
# => "Some value"
p o.another_key
# => "Another value"

Also, PhantomObject includes ActiveModel, and you can extend it to use validations, form builders, etc.