{"id":31790743,"url":"https://github.com/gkats/guaranteed","last_synced_at":"2025-10-10T16:29:26.322Z","repository":{"id":56875473,"uuid":"106426536","full_name":"gkats/guaranteed","owner":"gkats","description":"Tiny library that ensures you always have an object to act upon.","archived":false,"fork":false,"pushed_at":"2017-10-25T13:23:08.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T16:29:25.703Z","etag":null,"topics":["nullobject","ruby","ruby-gem"],"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/gkats.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":"2017-10-10T14:13:56.000Z","updated_at":"2022-04-03T15:49:52.000Z","dependencies_parsed_at":"2022-08-20T11:30:49.740Z","dependency_job_id":null,"html_url":"https://github.com/gkats/guaranteed","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gkats/guaranteed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fguaranteed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fguaranteed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fguaranteed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fguaranteed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkats","download_url":"https://codeload.github.com/gkats/guaranteed/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fguaranteed/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004706,"owners_count":26083750,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["nullobject","ruby","ruby-gem"],"created_at":"2025-10-10T16:29:23.080Z","updated_at":"2025-10-10T16:29:26.314Z","avatar_url":"https://github.com/gkats.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# guaranteed\n\n\u003e Give me something for nothing!\n\n## What is this?\n\nGuaranteed is a tiny library that ensures you always have an object to act upon. By eliminating continual checks for your objects' capabilities you can focus on your code's functionality.\n\nGuaranteed's primary goal is to __eliminate nil checks__.\n\n## Hmmm... I'm not sure I need this\n\nHey, I'm with you here, you probably don't. Consider this a \"nice to have\" library. But the truth is that using the library can lead to much cleaner designs. Plus, it's almost zero overhead for your project. All you need is Ruby.\n\nHere's the basic usage. Let's fire up `irb` and illustrate a frequent problem we face when coding.\n\n```ruby\n# The most explicit approach\n# Too verbose!\ndef username\n  user.nil? ? nil : user.name\nend\n\n# An improvement (arguably)\n# What if the name attribute should return a boolean?\ndef username\n  user \u0026\u0026 user.name\nend\n\n# Rails developers think this is a neat trick :(\ndef username\n  user.try(:name)\nend\n\n# Guaranteed to the rescue!\ndef username\n  Guaranteed.Object(user).name\nend\n```\n\n## I'm still not convinced\n\nThe above example is just scratching the surface of Guaranteed's abilities. Let's take a look at some more interesting examples.\n\nMost common Ruby methods on objects are supported. They follow Ruby's implicit type conversions for an instance of [NilClass](https://ruby-doc.org/core-2.3.0/NilClass.html).\n\n```ruby\nobject = Guaranteed.Object(nil)\n\nobject.nil?     # =\u003e true\n!object         # =\u003e true\nobject.to_a     # =\u003e []\nobject.to_h     # =\u003e {}\nobject.to_s     # =\u003e ''\nobject.to_f     # =\u003e 0.0\nobject.to_i     # =\u003e 0\nobject.empty?   # =\u003e true\n```\n\nNeed method chaining? You're covered.\n\n```ruby\nobject = Guaranteed.Object(nil)\n\nobject.this.will.definitely.not.work!\n# =\u003e Returns self\n```\n\nAgreed, this amount of method chaining breaks the [Law of Demeter](https://en.wikipedia.org/wiki/Law_of_Demeter). Sometimes reality hits you hard in the face though. Let's try the above example using [ActiveSupport::Object](http://api.rubyonrails.org/classes/Object.html).\n\n```ruby\n# Ugh..\nobject.try(:this).try(:will).try(:definitely).try(:not).try(:work!)\n# =\u003e nil\n```\n\nBonus Ruby idiom that's supported.\n\n```ruby\nobject = Guaranteed.Object(nil)\n\nobject.tap do |o|\n  o.name = 'Homer Simpson'\n  o.save!\nend\n# =\u003e Returns self\n```\n\nUsing Rails? I've got good news for you! The library supports some Rails-specific methods too.\n\n```ruby\nobject = Guaranteed.Object(nil)\n\nobject.present?     # =\u003e false\nobject.as_json      # =\u003e nil\nobject.to_json      # =\u003e \"null\"\nobject.persisted?   # =\u003e false\n```\n\n## OK, I'm sold. How do I install it?\n\n```\n$ gem install guaranteed\n# or add it to your Gemfile\ngem 'guaranteed', '~\u003e 0.1.0'\n```\n\n## Can I contribute?\n\nYes, please. Feel free to fork the project and create your own branches. Consider creating a pull request back to this repo.\n\nRemember, you can run the tests with\n\n```\n$ rake\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkats%2Fguaranteed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkats%2Fguaranteed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkats%2Fguaranteed/lists"}