GitHub

Original file line numberDiff line numberDiff line change

@@ -132,16 +132,20 @@ def initialize(obj=NONE, meth=:each, *args, **kwd, &block)

132132

@stop_exc = false

133133

end

134134
135-

attr_accessor :obj, :meth, :args, :kwd

136-

attr_reader :fib

137-
138135

def initialize_copy(obj)

139136

raise TypeError, "can't copy type #{obj.class}" unless obj.kind_of? Enumerator

140-

raise TypeError, "can't copy execution context" if obj.fib

141-

@obj = obj.obj

142-

@meth = obj.meth

143-

@args = obj.args

144-

@kwd = obj.kwd

137+

raise TypeError, "can't copy execution context" if obj.instance_eval{@fib}

138+

meth = args = kwd = fib = nil

139+

obj.instance_eval {

140+

obj = @obj

141+

meth = @meth

142+

args = @args

143+

kwd = @kwd

144+

}

145+

@obj = obj

146+

@meth = meth

147+

@args = args

148+

@kwd = kwd

145149

@fib = nil

146150

@lookahead = nil

147151

@feedvalue = nil

@@ -274,14 +278,14 @@ def each(*argv, &block)

274278

obj = self

275279

if 0 < argv.length

276280

obj = self.dup

277-

args = obj.args

281+

args = obj.instance_eval{@args}

278282

if !args.empty?

279283

args = args.dup

280284

args.concat argv

281285

else

282286

args = argv.dup

283287

end

284-

obj.args = args

288+

obj.instance_eval{@args = args}

285289

end

286290

return obj unless block

287291

enumerator_block_call(&block)

Read the original on github.com ↗