{"id":17257057,"url":"https://github.com/waterlink/restricted_struct","last_synced_at":"2025-07-27T02:05:12.600Z","repository":{"id":26143109,"uuid":"29588182","full_name":"waterlink/restricted_struct","owner":"waterlink","description":"RestrictedStruct gem: create Struct-s with private or protected attributes","archived":false,"fork":false,"pushed_at":"2015-02-06T13:43:44.000Z","size":252,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T10:13:00.851Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waterlink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-21T12:20:24.000Z","updated_at":"2015-02-06T13:39:13.000Z","dependencies_parsed_at":"2022-08-01T05:48:34.501Z","dependency_job_id":null,"html_url":"https://github.com/waterlink/restricted_struct","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Frestricted_struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Frestricted_struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Frestricted_struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Frestricted_struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waterlink","download_url":"https://codeload.github.com/waterlink/restricted_struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245622802,"owners_count":20645676,"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":[],"created_at":"2024-10-15T07:16:15.592Z","updated_at":"2025-03-26T08:40:32.548Z","avatar_url":"https://github.com/waterlink.png","language":"Ruby","readme":"# RestrictedStruct\n\n[![Build Status](https://travis-ci.org/waterlink/restricted_struct.svg?branch=master)](https://travis-ci.org/waterlink/restricted_struct)\n\nThis gem allows to use ruby's Struct, but automatically hides all the attributes as private or protected, which provides higher level of encapsulation.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'restricted_struct'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install restricted_struct\n\n## Usage\n\nInstead of doing this:\n\n```ruby\nclass Rectangle \u003c Struct.new(:x1, :y1, :x2, :y2)\n  protected :x1, :x1=, :y1, :y1=, :x2, :x2=, :y2, :y2=\n\n  # ...\nend\n```\n\none can do:\n\n```ruby\nclass Rectangle \u003c RestrictedStruct.new(:protected, :x1, :y1, :x2, :y2)\n  # ...\nend\n```\n\nAvailable access levels: `:private` and `:protected`.\n\n### Keyword arguments\n\n```ruby\nclass Rectangle \u003c RestrictedStruct.new(:protected, :x1, :y1, :x2, :y2, :color =\u003e :white)\n  # ...\nend\n```\n\nThis will create a struct with 5 fields: x1, y1, x2, y2 and color. But color will default to `:white` if not provided.\nAnd color can be assigned while instantiating a value of this class either as 5th parameter or as keyword argument, i.e.:\n\n```ruby\nrect = Rectangle[20, 30, 60, 50, :red]\n# is the same as:\nrect = Rectangle[20, 30, 60, 50, :color =\u003e :red]\n```\n\nBy the way, nothing forbids you from specifying any fields as keyword arguments:\n\n```ruby\nrect = Rectangle[20, 30, :x2 =\u003e 60, :y2 =\u003e 50]\n# or even all of them:\nrect = Rectangle[:x1 =\u003e 20, :y1 =\u003e 30, :x2 =\u003e 60, :y2 =\u003e 50, :color =\u003e :black]\n```\n\nJust be careful when specifying the same fields simultaneously as normal params and as part of keyword arguments hash, for example:\n\n```ruby\nrect = Rectangle[20, 30, 60, 50, :x2 =\u003e 55]\n# is essentially the same as\nrect = Rectangle[20, 30, 55, 50]\n```\n\nWhich means 3rd argument was overwritten by corresponding keyword argument.\n\n## Contributing\n\n1. Fork it ( https://github.com/waterlink/restricted_struct/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Alexey Fedorov](https://github.com/waterlink)\n- [Anselm Helbig](https://github.com/anselm-helbig-wimdu)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaterlink%2Frestricted_struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaterlink%2Frestricted_struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaterlink%2Frestricted_struct/lists"}