{"id":15605691,"url":"https://github.com/gangelo/immutable_struct_ex","last_synced_at":"2025-10-26T13:37:30.339Z","repository":{"id":57748713,"uuid":"523823913","full_name":"gangelo/immutable_struct_ex","owner":"gangelo","description":"ImmutableStructEx is yet another immutable struct. What makes ImmutableStructEx different, is that it allows you to create immutable structs in one step by default. In other words, other immutable struct gems force you to first define the struct, then instantiate the struct object; or, define the struct and instantiate the struct object via chaining.","archived":false,"fork":false,"pushed_at":"2024-10-28T20:12:10.000Z","size":51,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T21:03:11.620Z","etag":null,"topics":["gem","gems","immutable","immutable-datastructures","immutable-objects","immutable-store","immutable-struct","immutables","ruby","ruby-gem","ruby-gems","ruby-struct","ruby-structs","struct"],"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/gangelo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2022-08-11T18:11:29.000Z","updated_at":"2024-03-31T04:12:01.000Z","dependencies_parsed_at":"2024-08-03T23:34:33.791Z","dependency_job_id":"bdf19d1b-5c9f-4dfa-b957-b22d65cb021f","html_url":"https://github.com/gangelo/immutable_struct_ex","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"f63c5a75e4b5c4063d769b6607dca12e328af9c0"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gangelo%2Fimmutable_struct_ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gangelo%2Fimmutable_struct_ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gangelo%2Fimmutable_struct_ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gangelo%2Fimmutable_struct_ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gangelo","download_url":"https://codeload.github.com/gangelo/immutable_struct_ex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251814303,"owners_count":21648242,"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":["gem","gems","immutable","immutable-datastructures","immutable-objects","immutable-store","immutable-struct","immutables","ruby","ruby-gem","ruby-gems","ruby-struct","ruby-structs","struct"],"created_at":"2024-10-03T04:11:29.747Z","updated_at":"2025-10-26T13:37:30.243Z","avatar_url":"https://github.com/gangelo.png","language":"Ruby","readme":"[![Ruby](https://github.com/gangelo/immutable_struct_ex/actions/workflows/ruby.yml/badge.svg)](https://github.com/gangelo/immutable_struct_ex/actions/workflows/ruby.yml)\r\n[![GitHub version](http://badge.fury.io/gh/gangelo%2Fimmutable_struct_ex.svg?refresh=8)](https://badge.fury.io/gh/gangelo%2Fimmutable_struct_ex)\r\n[![Gem Version](https://badge.fury.io/rb/immutable_struct_ex.svg?refresh=8)](https://badge.fury.io/rb/immutable_struct_ex)\r\n[![](http://ruby-gem-downloads-badge.herokuapp.com/immutable_struct_ex?type=total)](http://www.rubydoc.info/gems/immutable_struct_ex/)\r\n[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/immutable_struct_ex/)\r\n[![Report Issues](https://img.shields.io/badge/report-issues-red.svg)](https://github.com/gangelo/immutable_struct_ex/issues)\r\n[![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#license)\r\n\r\n# immutable_struct_ex\r\n\r\nimmutable_struct_ex is yet another immutable struct. What makes immutable_struct_ex different, is that it allows you to create immutable structs in one step _by default_. In other words, other immutable struct gems force you to first define the struct, then instantiate the struct object; or, define the struct and instantiate the struct object via chaining. For example:\r\n\r\n## Other Immutable Structs\r\n\r\n```ruby\r\n# How OTHER immutable structs declare and instantiate, two steps...\r\nsome_immutable_struct = SomeImmutableStruct.new(:first, :last, :phone)\r\nsome_immutable_struct.new(first: 'John', last: 'Doe', phone: '(201) 230-7281')\r\n\r\n# How OTHER immutable structs chain...\r\nsome_immutable_struct = SomeImmutableStruct.new(:first, :last, :phone)\r\n                          .new(first: 'John', last: 'Doe', phone: '(201) 230-7281')\r\n```\r\n\r\n## immutable_struct_ex\r\nimmutable_struct_ex allows you to instantiate and initialize the object _in one step:_\r\n\r\n```ruby\r\nimmutable_struct_ex = ImmutableStructEx.new(first: 'John', last: 'Doe', phone: '(201) 230-7281')\r\n\r\nimmutable_struct_ex.first\r\n#=\u003e 'John'\r\n\r\nimmutable_struct_ex[:first]\r\n#=\u003e 'John'\r\n\r\nimmutable_struct_ex.last\r\n#=\u003e 'Doe'\r\n\r\nimmutable_struct_ex.phone\r\n#=\u003e '(201) 230-7281'\r\n```\r\n### Immutable\r\nLike other immutable structs, immutable_struct_ex also removes methods that change the state of the object, making it _immutable:_\r\n\r\n```ruby\r\nimmutable_struct_ex.first = 'Joe'\r\n#=\u003e NoMethodError: undefined method `first='...\r\n\r\nimmutable_struct_ex[:first] = 'Joe'\r\n#=\u003e NoMethodError: undefined method `[]='...\r\n```\r\n\r\n### Blocks\r\nAlso, not unlike other immutable structs, immutable_struct_ex also allows you to pass a block:\r\n\r\n```ruby\r\n# With a block\r\nimmutable_struct_ex = ImmutableStructEx.new(first: 'John', last: 'Doe', phone: '(201) 230-7281') do\r\n  def john?\r\n    first == 'John'\r\n  end\r\nend\r\n\r\nimmutable_struct_ex.john?\r\n#=\u003e true\r\n```\r\n\r\n### Other Examples\r\nGet creative. Below is an example of an immutable struct that provides _redaction_:\r\n\r\n```ruby\r\n# Redactable, immutable struct\r\nuser = {\r\n  username: 'jdoe',\r\n  password: 'p@55w0rD',\r\n  ssn: '123-70-9182'\r\n}\r\n\r\nimmutable_struct_ex = ImmutableStructEx.new(**user) do\r\n  REDACT = %i(password ssn).freeze\r\n\r\n  def inspect\r\n    to_s\r\n  end\r\n\r\n  def to_s\r\n    super.to_s.tap do |string|\r\n      REDACT.each do |redact|\r\n        string.gsub!(/( #{Regexp.quote(redact.to_s)}=\")(.*?)(\")/, '\\1[REDACTED]\\3')\r\n      end\r\n    end\r\n  end\r\n\r\n  def to_h\r\n    super.to_h.tap do |hash|\r\n      REDACT.each { |redact| hash[redact] = '[REDACTED]' }\r\n    end\r\n  end\r\nend\r\n\r\nimmutable_struct_ex.inspect\r\n#=\u003e \"#\u003cstruct username=\\\"jdoe\\\", password=\\\"[REDACTED]\\\", ssn=\\\"[REDACTED]\\\"\u003e\"\r\n\r\nimmutable_struct_ex.to_h\r\n#=\u003e {:username=\u003e\"jdoe\", :password=\u003e\"[REDACTED]\", :ssn=\u003e\"[REDACTED]\"}\r\n```\r\n\r\n## Installation\r\n\r\nAdd this line to your application's Gemfile:\r\n\r\n```ruby\r\ngem 'immutable_struct_ex'\r\n```\r\n\r\nAnd then execute:\r\n\r\n    $ bundle\r\n\r\nOr install it yourself as:\r\n\r\n    $ gem install immutable_struct_ex\r\n\r\n## Development\r\n\r\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\r\n\r\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).\r\n\r\n## Contributing\r\n\r\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/immutable_struct_ex. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\r\n\r\n## License\r\n\r\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\r\n\r\n## Code of Conduct\r\n\r\nEveryone interacting in the ImmutableStructEx project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/immutable_struct_ex/blob/master/CODE_OF_CONDUCT.md).\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgangelo%2Fimmutable_struct_ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgangelo%2Fimmutable_struct_ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgangelo%2Fimmutable_struct_ex/lists"}