Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bench
lib
prof
spec
test
.gitignore
.rspec
.ruby-gemset
.ruby-version
.travis.yml
CHANGELOG.md
Gemfile
INSTALLING.md
README.md
Rakefile
USING.md
astruct.gemspec

README.md

astruct

  • Quality
  • Coverage
  • Build
  • Dependencies
  • Downloads
  • Tags
  • Releases
  • Issues
  • License
  • Version

AltStruct is a direct alternative to OpenStruct, the Ruby class from the Standard Library.

Using

You can use AltStruct exactly like OpenStruct:

require "astruct"

person = AltStruct.new(name: "Kurtis Rainbolt-Greene", age: 23, friends: [])
person.name
  # => "Kurtis Rainbolt-Greene"
person.age
  # => 23
person.location = "Los Angeles, CA"
person.location
  # => "Los Angeles, CA"

class Person < AltStruct
  # ...Custom logic...
end

person2 = Person.new(name: "Angela Englund")
person2.name
  # => "Angela Englund"

Here is where AltStruct differs:

# We have access to a merge method, like Hash. It doesn't overwrite the entire
# tree anymore, like OpenStruct#marshal_load.
person.merge({ name: "James Caldwell" })
person.name
  # => "James Caldwell"
person.age
  # => 23

# You no longer completely overwrite core Ruby object methods:
person.object_id
  # => ...
person.inspect
  # => ...
person.object_id = 1
person.object_id
  # => 1
person.inspect
  # => ...
person.__object_id__
# You can now mixin behavior instead of forcing inheritence:
class Person
  include AltStruct::Behavior
end

We've also fixed some problematic bugs.

Installing

Add this line to your application's Gemfile:

gem "astruct", "~> 3.0"

And then execute:

$ bundle

Or install it yourself with:

$ gem install astruct

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Changelog

  • 1.0.0: Initial release

Conduct

As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the Contributor Covenant, version 1.0.0, available at http://contributor-covenant.org/version/1/0/0/

License

Copyright (c) 2014, 2015 Kurtis Rainbolt-Greene

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.