来自 金沙js77888 2019-06-19 04:50 的文章
当前位置: 金沙js77888 > 金沙js77888 > 正文

Add method to a variable only

company_name = 'Software'
def company_name.legalese
  return '#{self} is a registered trademark.'
end

company_name.legalese
# => 'Homegrown Software is a registered trademark of ConglomCo International.'
'Some Other Company'.legalese
# NoMethodError: undefined method 'legalese' for 'Some Other Company':String

本文由金沙js77888发布于金沙js77888,转载请注明出处:Add method to a variable only

关键词: js333金沙娱乐 Ruby Class