English 中文(简体)
试图在阿雷拉分流中重新计算+=似乎没有任何东西?
原标题:Trying to re-define += in an Array subclass doesn t seem to do anything?

在阿雷拉分级(调整了一些投入价值编码的阵列) I ve defined #concat to ensure Value are forcedd. 由于没有人使用<代码>#concat,因此更有可能使用<代码>#+=。 我试图将<代码>#+=至#concat包括在内,但似乎从未援引过。 任何想法?

请注意,如果该编码似乎不做我描述的内容,则该编码实际上总是与某一超级舱的物体(后者接受建筑商的投入)。 它是内部的、私人的APIC的一部分。

  class CoercedArray < Array
    def initialize(type)
      super()
      @type = type
    end

    def push(object)
      object = @type.new(object) unless object.kind_of?(@type)
      super
    end

    def <<(object)
      push(object)
    end

    def concat(other)
      raise ArgumentError, "Cannot append #{other.class} to #{self.class}<#{@type}>" unless other.kind_of?(Array)
      super(other.inject(CoercedArray.new(@type)) { |ary, v| ary.push(v) })
    end

    alias :"+=" :concat
  end

<代码>#concat正在正确操作,但#+=似乎完全绕过。

最佳回答

a += b> 以来,为a = a + b而 s糖。 页: 1

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签