Hi!
Im trying to test my rails applications javascript using jruby 1.3.1,celerity and culerity. The application itself runs under ruby 1.8.7 + phusion passenger (and runs fine, sans test :))
Everything installation-wise works fine but my app uses some_enumerable.each_slice(10)
to split a larger array into smaller subarray with 10 elelents each.
Celerity need jruby and jruby is only ruby 1.8.6 compatible and therefor doesnt support a blockless each_slice.
So I'm thinking about defining an initalizer which adds this functionality if RUBY_PLATFORM == "java " (or RUBY_VERSION < 1.8.7
)
This far I got (defunct code of cause):
if true #ruby 1.8.6
module Enumerable
alias_method :original_each_slice, :each_slice
def each_slice(count, &block)
# call original method in 1.8.6
if block_given?
original_each_slice(count, block)
else
self.enum_for(:original_each_slice, count).to_a
end
end
end
end
This code obviously is not working and I would really appreciate someone pointing me to a solution.
Thanks!
Update: Solution thanks to sepp2k for pointing me to my errors:
if RUBY_VERSION < "1.8.7"
require 'enumerator'
module Enumerable
alias_method :original_each_slice, :each_slice
def each_slice(count, &block)
if block_given?
# call original method when used with block
original_each_slice(count, &block)
else
# no block -> emulate
self.enum_for(:original_each_slice, count)
end
end
end
end