Skip to content

Commit 735fa24

Browse files
committed
mruby-enumerator: remove internal attribute methods; ref #6068
Removed methods: obj, args, kwd, meth, fib.
1 parent 298155d commit 735fa24

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

mrbgems/mruby-enum-lazy/mrblib/lazy.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ def to_enum(meth=:each, *args, &block)
4747
raise ArgumentError, "undefined method #{meth}"
4848
end
4949
lz = Lazy.new(self, &block)
50-
lz.obj = self
51-
lz.meth = meth
52-
lz.args = args
50+
obj = self
51+
lz.instance_eval {
52+
@obj = obj
53+
@meth = meth
54+
@args = args
55+
}
5356
lz
5457
end
5558
alias enum_for to_enum

mrbgems/mruby-enumerator/mrblib/enumerator.rb

Lines changed: 14 additions & 10 deletions
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)

0 commit comments

Comments
 (0)