{"id":17773920,"url":"https://github.com/svenfuchs/obj","last_synced_at":"2025-04-01T16:18:21.484Z","repository":{"id":56893600,"uuid":"182830873","full_name":"svenfuchs/obj","owner":"svenfuchs","description":"Struct replacement","archived":false,"fork":false,"pushed_at":"2022-11-02T22:47:31.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T23:17:11.034Z","etag":null,"topics":["objects","ruby","struct"],"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/svenfuchs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-22T17:00:38.000Z","updated_at":"2022-11-02T22:47:34.000Z","dependencies_parsed_at":"2022-08-21T01:20:19.784Z","dependency_job_id":null,"html_url":"https://github.com/svenfuchs/obj","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fobj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fobj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fobj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fobj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svenfuchs","download_url":"https://codeload.github.com/svenfuchs/obj/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246668904,"owners_count":20814744,"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":["objects","ruby","struct"],"created_at":"2024-10-26T21:47:17.071Z","updated_at":"2025-04-01T16:18:21.463Z","avatar_url":"https://github.com/svenfuchs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Obj [![Build Status](https://travis-ci.org/svenfuchs/obj.svg?branch=master)](https://travis-ci.org/svenfuchs/obj)\n\nA Struct replacement that allows default arguments, and omits the\nhash-style API that Struct implements.\n\n## Installation\n\n```\ngem install ruby-obj\n```\n\n## Usage\n\n```ruby\nrequire 'obj'\n\nclass One \u003c Obj.new(:one, two: :default)\nend\n\nobj = One.new(1)\nobj.one  # =\u003e 1\nobj.one? # =\u003e true\nobj.two  # =\u003e :default\nobj.two? # =\u003e true\n\nobj = One.new(nil)\nobj.one? # =\u003e false\n```\n\nModules included to `Obj` are propagated to all instances:\n\n```ruby\nmodule Foo\n  def foo\n  end\nend\n\nObj.include(Foo)\n\nclass One \u003c Obj.new(:one)\nend\n\none = One.new(1)\none.respond_to?(:foo) # =\u003e true\n```\n\n# Benchmark\n\n`Obj` is marginally slower than `Struct` (which is implemented in C):\n\n```ruby\nrequire 'benchmark'\nrequire 'obj'\n\nn = 1_000_000\n\nstr = Struct.new(:foo)\nobj = Obj.new(:foo)\n\nBenchmark.bm(10) do |b|\n  b.report('str:') { n.times { str.new(:foo).foo } }\n  b.report('obj:') { n.times { obj.new(:foo).foo } }\nend\n```\n\n```\n                 user     system      total        real\nstr:         0.180000   0.000000   0.180000 (  0.174254)\nobj:         0.180000   0.000000   0.180000 (  0.181985)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvenfuchs%2Fobj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvenfuchs%2Fobj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvenfuchs%2Fobj/lists"}