Range#step doesn't work with custom object that only respond to #succ, #<=>
---------------------------------------------------------------------------
Key: JRUBY-2316
URL: http://jira.codehaus.org/browse/JRUBY-2316
Project: JRuby
Issue Type: Bug
Environment: Latest JRuby 1.1RC3
Reporter: Vladimir Sizikov
Assignee: Thomas E Enebo
Fix For: JRuby 1.1RC3
JRuby fails the following unit tests from Ruby 1.9:
test/ruby/test_range.rb
jruby test_range.rb -n test_step
1) Error:
test_step(TestRange):
NoMethodError: undefined method `<=' for #<Object:0x8390b0>
test_range.rb:150:in `step'
test_range.rb:150:in `test_step'
The test code there:
{noformat}
o1 = Object.new
o2 = Object.new
def o1.<=>(x); -1; end
def o2.<=>(x); 0; end
assert_raise(TypeError) { (o1..o2).step(1) { } }
class << o1; self; end.class_eval do
define_method(:succ) { o2 }
end
a = []
(o1..o2).step(1) {|x| a << x }
assert_equal([o1, o2], a)
{noformat}
Basically, JRuby uses "<=" method, while MRI uses <=>.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email