What is the difference between Methods and Attributes in Ruby?

后端 未结 5 510
抹茶落季
抹茶落季 2021-01-31 10:11

Can you give me an example?

5条回答
  •  日久生厌
    2021-01-31 10:45

    I have heard the word "attribute" refer, in Ruby-specific circles, to any method which does not take arguments.

    class Batman
    
      def favorite_ice_cream
         [
           'neopolitan', 
           'chunky monkey', 
           'chocolate', 
           'chocolate chip cookie dough', 
           'whiskey'
         ].shuffle[0]         
      end
    
    end
    

    In the above, my_newest_batman.favorite_ice_cream would be an attribute.

提交回复
热议问题