{"id":19523268,"url":"https://github.com/niklasb/ruby-dynamic-binding","last_synced_at":"2025-04-26T09:32:35.375Z","repository":{"id":2948053,"uuid":"3961515","full_name":"niklasb/ruby-dynamic-binding","owner":"niklasb","description":"Implements a flexible form of dynamic binding to Ruby which allows to run a Proc inside a custom name lookup context","archived":false,"fork":false,"pushed_at":"2022-06-29T17:35:50.000Z","size":5,"stargazers_count":26,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T10:47:01.471Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niklasb.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":"2012-04-08T00:34:50.000Z","updated_at":"2022-07-22T06:00:15.000Z","dependencies_parsed_at":"2022-07-21T21:32:49.774Z","dependency_job_id":null,"html_url":"https://github.com/niklasb/ruby-dynamic-binding","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/niklasb%2Fruby-dynamic-binding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasb%2Fruby-dynamic-binding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasb%2Fruby-dynamic-binding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasb%2Fruby-dynamic-binding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niklasb","download_url":"https://codeload.github.com/niklasb/ruby-dynamic-binding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250967510,"owners_count":21515612,"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-11-11T00:42:54.387Z","updated_at":"2025-04-26T09:32:32.106Z","avatar_url":"https://github.com/niklasb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Overview\n\nThis is a small experiment triggered by a [Stackoverflow\nquestion](http://stackoverflow.com/questions/10058996/about-changing-binding-of-a-proc-in-ruby)\nwhich realizes a certain, flexible form of dynamic binding in Ruby.\n\nIn particular, using this we can run an existing `Proc` instance in a new\ncontext:\n\n    require 'dynamic_binding'\n\n    l = lambda { |a| a + foo }\n    foo = 2\n    l.call_with_binding(binding, 1)  # =\u003e 3\n\nIn addition to `Proc#call_with_binding`, we can also build up much more complex\nlookup scenarios:\n\n    require 'dynamic_binding'\n\n    l = lambda { |a| local + func(2) + some_method(1) + var + a }\n\n    local = 1\n    def func(x) x end\n\n    class Foo \u003c Struct.new(:add)\n      def some_method(x) x + add end\n    end\n\n    stack = DynamicBinding::LookupStack.new\n    stack.push_binding(binding)\n    stack.push_instance(Foo.new(2))\n    stack.push_hash(:var =\u003e 4)\n\n    p stack.run_proc(l, 5)  # =\u003e 15\n\nNote that the lambda is defined at the *beginning* of the code, so none of\nthe names it accesses are actually captured by its closure!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasb%2Fruby-dynamic-binding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniklasb%2Fruby-dynamic-binding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasb%2Fruby-dynamic-binding/lists"}