Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
方法未定义错误-Ruby_Ruby_Class_Methods - Fatal编程技术网

方法未定义错误-Ruby

方法未定义错误-Ruby,ruby,class,methods,Ruby,Class,Methods,这是一个数字分区的代码,在最后一节中我遇到了麻烦,因为由于方法错误,我无法将数字分开 class Num_Part def Particiones n //method for the number partititons if n == 1 return [[1]] elsif n < 1 return [[]] end Particiones(n) listaparticiones = [] for

这是一个数字分区的代码,在最后一节中我遇到了麻烦,因为由于方法错误,我无法将数字分开

class Num_Part

  def Particiones n     //method for the number partititons
    if n == 1
      return [[1]]
    elsif n < 1
      return [[]]
    end
    Particiones(n)
    listaparticiones = []
    for k in (n)..downto(0)
      cola= Particiones(n) - k
      for x in cola
        particion= [k] + x
      end
      listaparticiones << particion
    end
    return listaparticiones
  end

end

puts "Ingrese el Valor de N: \n" // this is where i ask for the value or the 
n =Integer(gets.chomp)            //number to be parted
lista = Particiones(n)

    print "\n cantidad de particiones: " +String(lista.size)

lista.each do |i|
  print [i]
end
obj = Num_Part.new
obj.Particiones(n)
class Num\u部分
def Particiones n//数字部分的方法
如果n==1
返回[[1]]
elsifn<1
返回[]]
结束
粒子(n)
listaparticiones=[]
对于k in(n)…向下至(0)
cola=粒子(n)-k
可乐里的x
粒子=[k]+x
结束
listaparticiones这里定义了一个实例方法

您将其称为类方法:

因此,要么将定义更改为
def self.partitions n
,要么将调用更改为
Num\u Part.new.partitions(n)

只是旁注,你的名字不符合惯例。例如,方法通常都是小写的

,在这里您定义了一个实例方法

您将其称为类方法:

因此,要么将定义更改为
def self.partitions n
,要么将调用更改为
Num\u Part.new.partitions(n)

只是旁注,你的名字不符合惯例。例如,方法通常都是小写的

class Num_Part

  def Particiones n 
Num_Part.Particiones(n)