{"id":13747463,"url":"https://github.com/arturoherrero/ofstruct","last_synced_at":"2025-05-09T08:33:18.948Z","repository":{"id":29364541,"uuid":"32899129","full_name":"arturoherrero/ofstruct","owner":"arturoherrero","description":"OpenFastStruct is a data structure, similar to an OpenStruct but faster.","archived":false,"fork":false,"pushed_at":"2023-01-26T12:07:02.000Z","size":26,"stargazers_count":56,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-11T21:22:14.831Z","etag":null,"topics":["openstruct","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/ofstruct","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/arturoherrero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-26T00:39:33.000Z","updated_at":"2023-08-17T09:30:42.000Z","dependencies_parsed_at":"2023-02-14T17:01:44.123Z","dependency_job_id":null,"html_url":"https://github.com/arturoherrero/ofstruct","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturoherrero%2Fofstruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturoherrero%2Fofstruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturoherrero%2Fofstruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturoherrero%2Fofstruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arturoherrero","download_url":"https://codeload.github.com/arturoherrero/ofstruct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224849245,"owners_count":17380078,"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":["openstruct","ruby","ruby-gem"],"created_at":"2024-08-03T06:01:30.004Z","updated_at":"2024-11-15T21:30:32.181Z","avatar_url":"https://github.com/arturoherrero.png","language":"Ruby","readme":"# OpenFastStruct\n\n[![Code Climate](https://codeclimate.com/github/arturoherrero/ofstruct/badges/gpa.svg)](https://codeclimate.com/github/arturoherrero/ofstruct)\n[![Build Status](https://github.com/arturoherrero/ofstruct/workflows/Build/badge.svg?branch=master)](https://github.com/arturoherrero/ofstruct/actions)\n\nOpenStruct allows the creation of data objects with arbitrary attributes.\n\n**OpenFastStruct** is a data structure, similar* to an OpenStruct, that allows the\ndefinition of arbitrary attributes with their accompanying values. It benchmarks\n~3x slower than a Hash, but **it's ~4x faster than OpenStruct**.\n\n*An OpenFastStruct is not exactly like an OpenStruct, these are the main\ndifferences between them:\n- OpenFastStruct doesn't allow hash access like `person[:name]`.\n- OpenFastStruct doesn't provide marshalling.\n- OpenFastStruct allows infinite chaining of attributes \u003csup\u003e[example](#black-hole-object)\u003c/sup\u003e.\n\n\n## Installation\n\nInstall the gem:\n\n    $ gem install ofstruct\n\nUse the gem in a project managed with Bundler adding it into the Gemfile:\n\n    gem \"ofstruct\"\n\n\n## Examples\n\n### Basic usage\n\n```ruby\nrequire \"ofstruct\"\n\nperson = OpenFastStruct.new\nperson.name = \"John Smith\"\nperson.age  = 70\n\nputs person.name     # -\u003e \"John Smith\"\nputs person.age      # -\u003e 70\nputs person.address  # -\u003e #\u003cOpenFastStruct\u003e\n```\n\n### Initialize and update from a Hash\n\nAn OpenFastStruct employs a Hash internally to store the methods and values and\ncan even be initialized or updated with one:\n\n```ruby\nrequire \"ofstruct\"\n\nperson = OpenFastStruct.new(:name =\u003e \"John Smith\")\nputs person.name  # -\u003e \"John Smith\"\n\nperson.update(:name =\u003e \"David Smith\", :age =\u003e 70)\nputs person.name  # -\u003e \"David Smith\"\nputs person.age   # -\u003e 70\n```\n\n### Remove attributes\n\nRemoving the presence of a method requires the execution the `#delete_field`\nmethod as setting the property value to a new empty OpenFastStruct.\n\n```ruby\nrequire \"ofstruct\"\n\nperson = OpenFastStruct.new\nperson.name = \"John Smith\"\nperson.delete_field(:name)\nputs person.name  # -\u003e #\u003cOpenFastStruct\u003e\n```\n\n### *Black hole* object\n\nAn OpenFastStruct instance is a *black hole* object that supports infinite\nchaining of attributes.\n\n```ruby\nrequire \"ofstruct\"\n\nperson = OpenFastStruct.new\nperson.address.number = 4\nputs person.address.number  # -\u003e 4\n```\n\n\n## Benchmarks\n\nProbably you heard that you should never, ever use OpenStruct because the\nperformance penalty is prohibitive. You can use OpenFastStruct instead!\n\n#### Comparation between Hash, OpenFastStruct and OpenStruct:\n\n```\n$ ruby benchmark/hash_ofstruct_ostruct.rb\nCalculating -------------------------------------\n                Hash    25.518k i/100ms\n      OpenFastStruct    10.527k i/100ms\n          OpenStruct     3.236k i/100ms\n-------------------------------------------------\n                Hash    487.517k (±11.9%) i/s -      2.399M\n      OpenFastStruct    159.952k (± 4.0%) i/s -    800.052k\n          OpenStruct     45.602k (± 4.7%) i/s -    229.756k\n\nComparison:\n                Hash:   487516.9 i/s\n      OpenFastStruct:   159952.4 i/s - 3.05x slower\n          OpenStruct:    45601.6 i/s - 10.69x slower\n```\n\n#### Comparation between RSpec Stubs, OpenFastStruct and OpenStruct:\n\n```\n$ ruby benchmark/double_ofstruct_ostruct.rb\nCalculating -------------------------------------\n         RSpec Stubs   103.000  i/100ms\n      OpenFastStruct   108.000  i/100ms\n          OpenStruct    45.000  i/100ms\n-------------------------------------------------\n         RSpec Stubs    297.809  (±17.1%) i/s -      1.545k in   5.346697s\n      OpenFastStruct    262.381  (±12.2%) i/s -      1.404k in   5.430345s\n          OpenStruct    185.150  (± 7.0%) i/s -    945.000\n\nComparison:\n         RSpec Stubs:      297.8 i/s\n      OpenFastStruct:      262.4 i/s - 1.14x slower\n          OpenStruct:      185.2 i/s - 1.61x slower\n```\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farturoherrero%2Fofstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farturoherrero%2Fofstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farturoherrero%2Fofstruct/lists"}