From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 316CB17DD993 for ; Mon, 19 Jan 2015 04:50:49 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 502AEB5D8C6 for ; Mon, 19 Jan 2015 04:49:12 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id AA22697A84B for ; Mon, 19 Jan 2015 04:49:12 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4a92_PhCMnU6 for ; Mon, 19 Jan 2015 04:49:12 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 732CC97A84E for ; Mon, 19 Jan 2015 04:49:12 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 6217595241E for ; Mon, 19 Jan 2015 04:49:10 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 5273A12043B; Mon, 19 Jan 2015 04:49:06 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id CC6A1120410 for ; Mon, 19 Jan 2015 04:49:01 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=zpNikTGkwMsmmZ3j9onB31cafKk=; b=e5IrYBqmElnRW5ozGE 7YYb83b7gutQKWLUqomiYjEJbYbed+pThB/AC3koFbBhpOaLk8CP2tYf+xKtwcQ/ BftgvFsMhT6RogSjr+Xi762sH9RTtkR3ibC91HcWXAGSZlrnYeKknX+iOYsmzqku CYGa9IhqCZCVKCvMlI3ieAcGs= Received: by filter0102p1mdw1.sendgrid.net with SMTP id filter0102p1mdw1.22109.54BC0E27A 2015-01-18 19:48:56.759761286 +0000 UTC Received: from herokuapp.com (ec2-54-145-66-252.compute-1.amazonaws.com [54.145.66.252]) by ismtpd-006 (SG) with ESMTP id 14afe974ef8.78cd.885e4 for ; Sun, 18 Jan 2015 19:48:56 +0000 (UTC) Date: Sun, 18 Jan 2015 19:48:56 +0000 From: fatblockshop@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 42103 X-Redmine-Project: common-ruby X-Redmine-Issue-Id: 7747 X-Redmine-Issue-Author: jballanc X-Redmine-Sender: seozmeoz X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: OOF Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS7dg4t/jssZeHcTA9FQxZtRSQjI1xrvT7gsPc 3jy1LAvX39/qR/7ROUQyeoOnUrwgcnYFX3CtW3I6C3Gr+5/3lDI7p5XEmswUWHbJP4tCq+pL9RE86E RgE/cBklLdTDZRPT0Gtw0cKwXp5ca+LlB7D8 X-ML-Name: ruby-core X-Mail-Count: 67677 Subject: [ruby-core:67677] [CommonRuby - Feature #7747] Expanded API for Binding semantics X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #7747 has been updated by ceren deren. nice one http://evenakliyatevden.net/ ---------------------------------------- Feature #7747: Expanded API for Binding semantics https://bugs.ruby-lang.org/issues/7747#change-51094 * Author: Joshua Ballanco * Status: Open * Priority: Normal * Assignee: ---------------------------------------- =begin Currently, the only way to create a new instance of Binding is to get a copy of the current scope's binding, or ask some other object for its binding. In either case, the binding object returned always has semantics identical to the original binding. In other words, a binding object used with eval is capable of (not necessarily an exhaustive list): * redefining methods on the binding target * defining new methods on the binding target * getting/setting instance variables * getting/creating new constants This feature proposal would introduce a new mechanism for creating a binding and adjusting its relationship with the source binding. For example, if you have a class (({Foo})) defined like so: class Foo def say puts "hello!" end end Then you would be able to create a new binding that ((*won't*)) propagate new definitions to the parent binding like so: new_binding = Binding.new(Foo) new_binding.propagate = false new_binding.eval("def shout; puts 'HI!'; end") Foo.new.say #=> "hello!" Foo.new.shout #=> No Method Error new_binding.eval("Foo.new.say") #=> "hello" new_binding.eval("Foo.new.shout") #=> "HI!" If, additionally, we introduce a way to merge or combine bindings, then this API could actually be used to implement refinements in pure Ruby like so (note I am also assuming that (({Binding#eval})) gains the ability to take a block): class Module def refine(klass, &block) @refined_bindings ||= {} refinement_binding = Binding.new(klass) refinement_binding.propagate = false refinement_binding.shadow = true refinement_binding.eval &block (@refined_bindings[self.name] ||= []) << refinement_binding end def using(mod) @refined_bindings[mod].each { |refinement| self.binding.merge(refinement) } end end Following is the preliminary list of additional APIs I am tentatively proposing (though I expect this to change with additional discussion): * (({Binding.new(an_object)})) - creates a new Binding object that "inherits" the binding of the argument; essentially equivalent to (({an_object.send(:binding).dup})) * (({Binding#propagate}))/(({Binding#propagate=})) - boolean; determines whether new method, class, or Constant defs are propagated into the "parent" binding's scope * (({Binding#shadow}))/(({Binding#shadow=})) - boolean; sets whether or not new values for existing methods/constants/variables can be set * (({Binding#freeze})) - causes the Binding to capture all existing methods/constants/variables in scope at call time, and "disconnect" from the parent binding, so that any updates to definitions or values are no longer reflected into the "child" binding * (({Binding#merge(other_binding)})) - combines the method/constant/variable bindings in (({other_binding})) with the receiver; effectively shadows the "parent" of (({other_binding})) within the receiver binding =end -- https://bugs.ruby-lang.org/