Fixnum的未定义方法“介于”

Sté*_*ane 1 ruby ruby-on-rails

我有一个网址:

xxxx/xxx?status=2
Run Code Online (Sandbox Code Playgroud)

:status从URL 获得了参数的值,将其转换为整数,并尝试对其使用between方法:

params[:status].to_i.between.(0, 3)
Run Code Online (Sandbox Code Playgroud)

但我得到如下错误:

undefined method `between' for 1:Fixnum
Run Code Online (Sandbox Code Playgroud)

我检查了班级祖先:

params[:status].to_i.class.ancestors
# => [Fixnum, JSON::Ext::Generator::GeneratorMethods::Fixnum, Integer, Numeric, Comparable, Object, ActiveSupport::Dependencies::Loadable, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]
Run Code Online (Sandbox Code Playgroud)

我可以看到Comparable,所以我不明白为什么我不能这样做。

Pet*_*kov 5

你必须在方法名称错误:没有between,但between?

params[:status].to_i.between?(0, 3)
Run Code Online (Sandbox Code Playgroud)

检查Ruby Doc