Thanks for your answers,

On Fri, Nov 26, 2010 at 03:24, Shugo Maeda <shugo / ruby-lang.org> wrote:
> Hi,
>
> 2010/11/26 Magnus Holm <judofyr / gmail.com>:
>> Woah, this is very nice stuff! Some comments/questions:
>>
>> 1. Could you give an example of how it would behave if it had local
>> rebinding as in classbox?
>
> If it had local rebinding, the following code would print "Quux::Foo#bar".
>
> class Foo
> def bar
>  puts "Foo#bar"
> end
>
> def baz
>  bar
> end
> end
>
> module Quux
> refine Foo do
>  def bar
>   puts "Quux::Foo#bar"
>  end
> end
> end
>
> using Quux
> foo = Foo.new
> foo.baz

Thanks a lot. Could you explain why included modules are rebound though?


    class CharArray
      include Enumerable

      def initialize(str)
        @array = str.unpack("C*")  # Unpacks to integers
      end

      def each(&blk)
        @array.each(&blk)
      end

      def map
        res = []
        each { |val| res << yield(val) }
        res
      end
    end

    test = CharArray.new("Hello World")
    test.each { |x| p x }  # Prints a list of integers (expected)

    module CharArrayStr
      refine CharArray do
        def each
          super { |c| yield c.chr }
        end
      end
    end

    using CharArrayStr
    test.each   { |x| p x }  # Prints a list of strings (expected)
    test.map    { |x| p x }  # Prints a list of integers (exptected;
no local rebinding)
    test.select { |x| p x }  # Prints a list of strings?!