mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* eval.c (rb_using_module): activate refinements in the ancestors of
the argument module to support refinement inheritance by Module#include. [ruby-core:55671] [Feature #8571] * test/ruby/test_refinement.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									551fe2bddc
								
							
						
					
					
						commit
						72d3e2b102
					
				
					 4 changed files with 95 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,11 @@
 | 
			
		|||
Mon Jul  1 12:56:41 2013  Shugo Maeda  <shugo@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* eval.c (rb_using_module): activate refinements in the ancestors of
 | 
			
		||||
	  the argument module to support refinement inheritance by
 | 
			
		||||
	  Module#include.  [ruby-core:55671] [Feature #8571]
 | 
			
		||||
 | 
			
		||||
	* test/ruby/test_refinement.rb: related test.
 | 
			
		||||
 | 
			
		||||
Mon Jul  1 12:02:39 2013  Tanaka Akira  <akr@fsij.org>
 | 
			
		||||
 | 
			
		||||
	* bignum.c (rb_cstr_to_inum): Skip leading zeros.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										5
									
								
								NEWS
									
										
									
									
									
								
							
							
						
						
									
										5
									
								
								NEWS
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -46,6 +46,11 @@ with all sufficient information, see the ChangeLog file.
 | 
			
		|||
* pack/unpack (Array/String)
 | 
			
		||||
  * Q! and q! directives for long long type if platform has the type.
 | 
			
		||||
 | 
			
		||||
* toplevel
 | 
			
		||||
  * extended methods:
 | 
			
		||||
    * main.using activates refinements in the ancestors of the argument
 | 
			
		||||
      module to support refinement inheritance by Module#include.
 | 
			
		||||
 | 
			
		||||
=== Core classes compatibility issues (excluding feature bug fixes)
 | 
			
		||||
 | 
			
		||||
* IO
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										32
									
								
								eval.c
									
										
									
									
									
								
							
							
						
						
									
										32
									
								
								eval.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1118,19 +1118,43 @@ using_refinement(VALUE klass, VALUE module, VALUE arg)
 | 
			
		|||
    return ST_CONTINUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
rb_using_module(NODE *cref, VALUE module)
 | 
			
		||||
static void
 | 
			
		||||
using_module_recursive(NODE *cref, VALUE klass)
 | 
			
		||||
{
 | 
			
		||||
    ID id_refinements;
 | 
			
		||||
    VALUE refinements;
 | 
			
		||||
    VALUE super, module, refinements;
 | 
			
		||||
 | 
			
		||||
    Check_Type(module, T_MODULE);
 | 
			
		||||
    super = RCLASS_SUPER(klass);
 | 
			
		||||
    if (super) {
 | 
			
		||||
	using_module_recursive(cref, super);
 | 
			
		||||
    }
 | 
			
		||||
    switch (BUILTIN_TYPE(klass)) {
 | 
			
		||||
    case T_MODULE:
 | 
			
		||||
	module = klass;
 | 
			
		||||
	break;
 | 
			
		||||
 | 
			
		||||
    case T_ICLASS:
 | 
			
		||||
	module = RBASIC(klass)->klass;
 | 
			
		||||
	break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
	rb_raise(rb_eTypeError, "wrong argument type %s (expected Module)",
 | 
			
		||||
		 rb_obj_classname(klass));
 | 
			
		||||
	break;
 | 
			
		||||
    }
 | 
			
		||||
    CONST_ID(id_refinements, "__refinements__");
 | 
			
		||||
    refinements = rb_attr_get(module, id_refinements);
 | 
			
		||||
    if (NIL_P(refinements)) return;
 | 
			
		||||
    rb_hash_foreach(refinements, using_refinement, (VALUE) cref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
rb_using_module(NODE *cref, VALUE module)
 | 
			
		||||
{
 | 
			
		||||
    Check_Type(module, T_MODULE);
 | 
			
		||||
    using_module_recursive(cref, module);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
VALUE rb_refinement_module_get_refined_class(VALUE module)
 | 
			
		||||
{
 | 
			
		||||
    ID id_refined_class;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -875,6 +875,60 @@ class TestRefinement < Test::Unit::TestCase
 | 
			
		|||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  class Bar
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  module BarExt
 | 
			
		||||
    refine Bar do
 | 
			
		||||
      def x
 | 
			
		||||
        return "BarExt#x"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  module FooBarExt
 | 
			
		||||
    include FooExt
 | 
			
		||||
    include BarExt
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  module FooBarExtClient
 | 
			
		||||
    using FooBarExt
 | 
			
		||||
 | 
			
		||||
    def self.invoke_x_on(foo)
 | 
			
		||||
      return foo.x
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_module_inclusion
 | 
			
		||||
    foo = Foo.new
 | 
			
		||||
    assert_equal("FooExt#x", FooBarExtClient.invoke_x_on(foo))
 | 
			
		||||
    bar = Bar.new
 | 
			
		||||
    assert_equal("BarExt#x", FooBarExtClient.invoke_x_on(bar))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  module FooFoo2Ext
 | 
			
		||||
    include FooExt
 | 
			
		||||
    include FooExt2
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  module FooFoo2ExtClient
 | 
			
		||||
    using FooFoo2Ext
 | 
			
		||||
 | 
			
		||||
    def self.invoke_x_on(foo)
 | 
			
		||||
      return foo.x
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def self.invoke_y_on(foo)
 | 
			
		||||
      return foo.y
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_module_inclusion2
 | 
			
		||||
    foo = Foo.new
 | 
			
		||||
    assert_equal("FooExt2#x", FooFoo2ExtClient.invoke_x_on(foo))
 | 
			
		||||
    assert_equal("FooExt2#y Foo#y", FooFoo2ExtClient.invoke_y_on(foo))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def eval_using(mod, s)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue