{"id":28968573,"url":"https://github.com/culturehq/tiny_struct","last_synced_at":"2025-06-24T09:09:38.095Z","repository":{"id":26428582,"uuid":"108803351","full_name":"CultureHQ/tiny_struct","owner":"CultureHQ","description":"Build Struct classes that do less.","archived":false,"fork":false,"pushed_at":"2023-03-06T10:59:03.000Z","size":165,"stargazers_count":4,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-01T14:02:52.480Z","etag":null,"topics":["ruby","tool"],"latest_commit_sha":null,"homepage":null,"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/CultureHQ.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-10-30T04:55:32.000Z","updated_at":"2021-12-15T10:12:49.000Z","dependencies_parsed_at":"2023-07-15T15:45:33.021Z","dependency_job_id":null,"html_url":"https://github.com/CultureHQ/tiny_struct","commit_stats":null,"previous_names":["kddeisz/tiny_struct"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/CultureHQ/tiny_struct","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CultureHQ%2Ftiny_struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CultureHQ%2Ftiny_struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CultureHQ%2Ftiny_struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CultureHQ%2Ftiny_struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CultureHQ","download_url":"https://codeload.github.com/CultureHQ/tiny_struct/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CultureHQ%2Ftiny_struct/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261641027,"owners_count":23188434,"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","tool"],"created_at":"2025-06-24T09:09:21.046Z","updated_at":"2025-06-24T09:09:38.083Z","avatar_url":"https://github.com/CultureHQ.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinyStruct\n\n[![Build Status](https://github.com/CultureHQ/tiny_struct/workflows/Main/badge.svg)](https://github.com/CultureHQ/tiny_struct/actions)\n[![Gem Version](https://img.shields.io/gem/v/tiny_struct.svg)](https://github.com/CultureHQ/tiny_struct)\n\nOften we want simple Ruby classes that follow the pattern of accepting data as arguments to the initializer and storing them as `attr_readers`. For example:\n\n```ruby\nclass User\n  attr_reader :name, :email\n\n  def initialize(name, email)\n    @name = name\n    @email = email\n  end\n\n  def to_s\n    \"#{name} \u003c#{email}\u003e\"\n  end\nend\n\nuser = User.new('Harry Potter', 'hpotter@hogwarts.edu')\n# =\u003e #\u003cUser @name=\"Harry Potter\" @email=\"hpotter@hogwarts.edu\"\u003e\n```\n\nThis is pretty common, and more or less resembles a struct and an associated initializer in many other languages (see initializer lists in C++ or case classes in Scala).\n\nYou could refactor the above to inherit from Ruby's own `Struct` class, as in:\n\n```ruby\nclass User \u003c Struct.new(:name, :email)\n  def to_s\n    \"#{name} \u003c#{email}\u003e\"\n  end\nend\n```\n\nThis totally works! `Struct::new` returns a class, from which `User` then inherits. This pattern is great because it encapsulates the initialization and enforces a certain consistency over the way objects are created within a codebase.\n\nHowever, there is a certain amount of bloat that comes from using the `Struct` class. Ruby defines a number of enumerable and comparison methods to allow them to function more like structs in other languages. This is why we built `TinyStruct`, which is effectively the same thing as a `Struct` but it does much less:\n\n* In `Struct` classes all parameters are optional, in `TinyStruct` they are all required (encouraging explicit values for each member).\n* In `Struct` classes each parameter is accessible through an `attr_accessor`, in `TinyStruct` they are accessible through `attr_reader`s (encouraging more data encapsulation).\n* In `Struct` classes you can call all kinds of querying methods on the objects as if they were an enumerable of the various values they represent (e.g., `to_a`, `to_h`, `size`, `[]`, `values_at`, etc.), in `TinyStruct` none of these methods are defined (minifying the surface area of the class to encourage explicit method definitions if necessary).\n\nYou can use `TinyStruct` in the exact same way that you could use `Struct` (by inheriting from an object returned by the `::new` method.\n\nUse `Struct` if you need the flexibility and extra query methods provided by the constructor. If not, consider using `TinyStruct`.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'tiny_struct'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install tiny_struct\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/CultureHQ/tiny_struct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fculturehq%2Ftiny_struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fculturehq%2Ftiny_struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fculturehq%2Ftiny_struct/lists"}