Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

Location:
EcnlProtoTool/trunk/mruby-2.1.1
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-enum-lazy/mrblib/lazy.rb

    r331 r439  
    4444
    4545    def to_enum(meth=:each, *args, &block)
     46      unless self.respond_to?(meth)
     47        raise ArgumentError, "undefined method #{meth}"
     48      end
    4649      lz = Lazy.new(self, &block)
    4750      lz.obj = self
     
    7073    def reject(&block)
    7174      Lazy.new(self){|yielder, val|
    72         if not block.call(val)
     75        unless block.call(val)
    7376          yielder << val
    7477        end
     
    156159    end
    157160
     161    def uniq(&block)
     162      hash = {}
     163      Lazy.new(self){|yielder, val|
     164        if block
     165          v = block.call(val)
     166        else
     167          v = val
     168        end
     169        unless hash.include?(v)
     170          yielder << val
     171          hash[v] = val
     172        end
     173      }
     174    end
     175
    158176    alias force to_a
    159177  end
Note: See TracChangeset for help on using the changeset viewer.