Skip to content

Phobos98/phantom-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A Hash to object converter - allows you to convert complex Hashes into objects for more common use

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages