如何在类rails中添加关联

时间:2014-10-31 09:56:25

标签: ruby ruby-on-rails-4

我想做

@array_object.factets 

@array_object属于Class A

 class A
   factets = ['c','d','e']
 end

Class A未继承任何Active record

1 个答案:

答案 0 :(得分:0)

如果没有必要调用变量那么你可以很容易地做到:

class A
  def factets
     ['c','d','e']
  end
end

然后:

@array_object = A.new
@array_object.factets

单行代码的OR:

@array_object = A.new.factets