Class alias in Ruby

后端 未结 5 1365
温柔的废话
温柔的废话 2020-12-08 13:45

I am developing a new Rails app based on a similar existing one. In my old app, I have Coupon class, which is very similar to Ticket in my new app. I want to reuse all code

5条回答
  •  佛祖请我去吃肉
    2020-12-08 14:02

    Classes don't have names in Ruby. They are just objects assigned to variables, just like any other object. If you want to refer to a class via a different variable, assign it to a different variable:

    Foo = String
    

提交回复
热议问题