{"id":15877627,"url":"https://github.com/zimbatm/namespace.rb","last_synced_at":"2025-03-16T05:31:08.803Z","repository":{"id":1193556,"uuid":"1098525","full_name":"zimbatm/namespace.rb","owner":"zimbatm","description":"Experiment: Bringing namespaces to Ruby","archived":false,"fork":false,"pushed_at":"2023-12-15T11:42:50.000Z","size":10,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T05:23:16.532Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zimbatm.png","metadata":{"files":{"readme":"README.rdoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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":"2010-11-20T22:56:12.000Z","updated_at":"2021-09-16T05:00:26.000Z","dependencies_parsed_at":"2024-10-06T02:02:37.207Z","dependency_job_id":"7d1d36e9-3e18-4947-aa4e-4b556205d3b2","html_url":"https://github.com/zimbatm/namespace.rb","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"892c48b15fee3a4c19cc63ca1d946cacc51eab08"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimbatm%2Fnamespace.rb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimbatm%2Fnamespace.rb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimbatm%2Fnamespace.rb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zimbatm%2Fnamespace.rb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zimbatm","download_url":"https://codeload.github.com/zimbatm/namespace.rb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806032,"owners_count":20350773,"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":[],"created_at":"2024-10-06T02:02:30.165Z","updated_at":"2025-03-16T05:31:07.959Z","avatar_url":"https://github.com/zimbatm.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Namespaces for ruby\n\nIt is an experiment to bring namespaces to ruby. It is not quite clear yet\nwhy this would be useful, but it can be interesting nonetheless.\n\nThis system is inspired by the CommonJS and Python module systems, adapted\nfor the ruby particularities.\n\n\nBy loading the .rb files into a temporary module, it is possible to avoid\npolluting the global namespace and select what to import in the current module.\n\nFeatures:\n\n* Compatible with ruby 1.8.7 and 1.9.2 (and others?)\n* Possible to avoid namespace collision on the module level\n\nUnfeatures:\n\n* uses eval and other nasty ruby hacks\n* classes and namespaces don't mix well because `class X; \u003c\u003chere\u003e\u003e; end`\n  is a new context that doesn't inherit from it's parent.\n\n== Usage\n\nSee: +Namespace.open+\n\n    m = Namespace.open(\"hello::world\")\n    m.hello\n    #=\u003e \"hello world\"\n\nIn the context of \"hello/world.rb\" Namespace#import is made available as\na shortcut.\n\n    X = import \"another::module\"\n\n    def hello\n      X::Joiner.new(\"hello\", \"world\").to_s\n    end\n\nClasses and modules are also exported:\n\n    class Joiner\n      def initialize(*a)\n        @args = a\n      end\n      def to_s\n        @args.join(' ')\n      end\n    end\n\n== TODO\n\n* Handle circular dependencies ?\n* Avoid eval (but I don't see how)\n* I just learned that Kernel#load(path, wrap=true) will load the file in\n  an anonymous module.\n\n== Tricks\n\nA module can emulate the main object behavior by extending itself. In that way,\nit makes it's functions directly available to consumption.\n\n    module X\n      extend self\n      def test\n        \"x\"\n      end\n      test #=\u003e \"x\"\n    end\n\nTODO\n\n== Bikeshed\n\n* Should ruby \"namespaced\" modules have their own $LOAD_PATH and file extensions ?\n\n== Licence\n\nPublic domain\n\nCheers, Jonas\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzimbatm%2Fnamespace.rb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzimbatm%2Fnamespace.rb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzimbatm%2Fnamespace.rb/lists"}