Can someone explain the following code to me?

前端 未结 5 1735
故里飘歌
故里飘歌 2021-01-20 05:59

I am following along with the Rails 3 in Action book, and it is talking about override to_s in the model. The code is the following:

def to_s
           


        
5条回答
  •  悲&欢浪女
    2021-01-20 06:13

    This function is returning a string with the email and whether it they are an admin or user... ie

    user_1 = {:email => "test@email.com", :admin => true}
    

    so the call

    user_1.to_s 
    

    would return the string

    "test@email.com Admin"
    

提交回复
热议问题