{"id":13879160,"url":"https://github.com/ruby/ostruct","last_synced_at":"2025-05-14T14:08:23.820Z","repository":{"id":27796065,"uuid":"104867446","full_name":"ruby/ostruct","owner":"ruby","description":"OpenStruct implementation","archived":false,"fork":false,"pushed_at":"2025-04-30T00:21:43.000Z","size":199,"stargazers_count":124,"open_issues_count":15,"forks_count":32,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-30T01:26:12.908Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-09-26T09:52:34.000Z","updated_at":"2025-04-30T00:21:45.000Z","dependencies_parsed_at":"2023-09-29T08:34:24.480Z","dependency_job_id":"0da61684-3938-445c-afb0-4772be9affbd","html_url":"https://github.com/ruby/ostruct","commit_stats":{"total_commits":191,"total_committers":34,"mean_commits":5.617647058823529,"dds":0.6439790575916231,"last_synced_commit":"7319a3e27c51d16980b329e8a137cddd701992fe"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fostruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fostruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fostruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fostruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby","download_url":"https://codeload.github.com/ruby/ostruct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159761,"owners_count":22024564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby"],"created_at":"2024-08-06T08:02:11.754Z","updated_at":"2025-05-14T14:08:23.802Z","avatar_url":"https://github.com/ruby.png","language":"Ruby","readme":"# OpenStruct [![Version](https://badge.fury.io/rb/ostruct.svg)](https://badge.fury.io/rb/ostruct) [![Default Gem](https://img.shields.io/badge/stdgem-default-9c1260.svg)](https://stdgems.org/ostruct/) [![Test](https://github.com/ruby/ostruct/workflows/test/badge.svg)](https://github.com/ruby/ostruct/actions?query=workflow%3Atest)\n\nAn OpenStruct is a data structure, similar to a Hash, that allows the definition of arbitrary attributes with their accompanying values. This is accomplished by using Ruby's metaprogramming to define methods on the class itself.\n\n## Installation\n\nThe `ostruct` library comes pre-packaged with Ruby. No installation is necessary.\n\n## Usage\n\n```ruby\n  require \"ostruct\"\n\n  person = OpenStruct.new\n  person.name = \"John Smith\"\n  person.age  = 70\n\n  person.name      # =\u003e \"John Smith\"\n  person.age       # =\u003e 70\n  person.address   # =\u003e nil\n```\n\nAn OpenStruct employs a Hash internally to store the attributes and values and can even be initialized with one:\n\n```ruby\n  australia = OpenStruct.new(:country =\u003e \"Australia\", :capital =\u003e \"Canberra\")\n    # =\u003e #\u003cOpenStruct country=\"Australia\", capital=\"Canberra\"\u003e\n```\n\nHash keys with spaces or characters that could normally not be used for method calls (e.g. \u003ccode\u003e()[]*\u003c/code\u003e) will not be immediately available on the OpenStruct object as a method for retrieval or assignment, but can still be reached through the Object#send method.\n\n```ruby\n  measurements = OpenStruct.new(\"length (in inches)\" =\u003e 24)\n  measurements.send(\"length (in inches)\")   # =\u003e 24\n\n  message = OpenStruct.new(:queued? =\u003e true)\n  message.queued?                           # =\u003e true\n  message.send(\"queued?=\", false)\n  message.queued?                           # =\u003e false\n```\n\nRemoving the presence of an attribute requires the execution of the delete_field method as setting the property value to +nil+ will not remove the attribute.\n\n```ruby\n  first_pet  = OpenStruct.new(:name =\u003e \"Rowdy\", :owner =\u003e \"John Smith\")\n  second_pet = OpenStruct.new(:name =\u003e \"Rowdy\")\n\n  first_pet.owner = nil\n  first_pet                 # =\u003e #\u003cOpenStruct name=\"Rowdy\", owner=nil\u003e\n  first_pet == second_pet   # =\u003e false\n\n  first_pet.delete_field(:owner)\n  first_pet                 # =\u003e #\u003cOpenStruct name=\"Rowdy\"\u003e\n  first_pet == second_pet   # =\u003e true\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ruby/ostruct.\n\n## License\n\nThe gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Fostruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby%2Fostruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Fostruct/lists"}