From: muraken@... Date: 2018-03-15T06:35:38+00:00 Subject: [ruby-core:86124] [Ruby trunk Feature#13904][Assigned] getter for original information of Enumerator Issue #13904 has been updated by mrkn (Kenta Murata). Status changed from Rejected to Assigned Assignee changed from knu (Akinori MUSHA) to matz (Yukihiro Matsumoto) Following today's developers meeting, I propose to introduce a subclass of Enumerator. This is the example implementation of the subclass: ```ruby class Enumerator::ArithmeticSequence < Enumerator attr_reader :first # already in Enumerator attr_reader :last # newly introduced attr_reader :step # newly introduced def inspect # appropriate string representation of this class instances end end ``` `Integer#step` and `Range#step` of integer ranges should return the instance of `Enumerator::ArithmeticSequence` like: ```ruby p 1.step #=> (1.step) p 1.step(10) #=> (1.step(10)) p 1.step(10, 2) #=> (1.step(10, by:2)) p 1.step(by: 2) #=> (1.step(by:2)) p (1..10).step #=> (1.step(10)) p (1..10).step(2) #=> (1.step(10, by:2)) ``` I think introducing this class doesn't introduce incompatibility from the current behaviors, but increase the usefulness of the results of `Integer#step` and `Range#step`. ---------------------------------------- Feature #13904: getter for original information of Enumerator https://bugs.ruby-lang.org/issues/13904#change-70998 * Author: znz (Kazuhiro NISHIYAMA) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- At https://gitter.im/red-data-tools/ja?at=59b0aaa097cedeb04828e268 , mrkn says narray and pycall use internal information of ruby to check `Range#step(n)`. People of red-data-tools/ja suggest subclass of Enumerator. But I think it does not match Ruby's '������������������' (I don't know this word in English), so I suggest to add some methods to Enumerator class. proof of concept attached. Usage: ``` % irb -r irb/completion --simple-prompt >> e=(1..2).step(3) => # >> e.receiver => 1..2 >> e.method_name => :step >> e.arguments => [3] ``` `#method` is conflict with `Kernel#method`, so use `#method_name` instead. ---Files-------------------------------- poc.diff (1.42 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: