Ruby 如何从枚举器中排除第二个端点

Ruby 如何从枚举器中排除第二个端点,ruby,ienumerator,Ruby,Ienumerator,我需要一个枚举器,它迭代n从a到b-(b-a)/n.to_f()。我需要一个带有步骤(b-a)/n的左关闭右打开间隔。到\u f()。我怎样才能得到它 我使用a.step(b,(b-a)/n.to_f()),但是step返回一个枚举数,该枚举数迭代n+1数字,包括两端a和bdef get\u步骤(a,b,n) def get_steps(a,b,n) step = (b - a) / n.to_f a.step(b - step, step) # or a.step(nil, ste

我需要一个
枚举器
,它迭代
n
a
b-(b-a)/n.to_f()
。我需要一个带有步骤
(b-a)/n的左关闭右打开间隔。到\u f()
。我怎样才能得到它

我使用
a.step(b,(b-a)/n.to_f())
,但是
step
返回一个
枚举数
,该枚举数迭代
n+1
数字,包括两端
a
b
def get\u步骤(a,b,n)
def get_steps(a,b,n)
  step = (b - a) / n.to_f
  a.step(b - step, step)   # or a.step(nil, step).take(n)
end

get_steps(2,4,5)       #=> <Enumerator:... >
get_steps(2,4,5).to_a  #=> [2.0, 2.4, 2.8, 3.2, 3.6]
步骤=(b-a)/n到f a、 步骤(b-步骤,步骤)#或a.步骤(无,步骤)。采取(n) 结束 获取步骤(2,4,5)#=> 获取步骤(2,4,5)。到a=>[2.0,2.4,2.8,3.2,3.6]