婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Ruby 之 class 中的 private、 protected、public

Ruby 之 class 中的 private、 protected、public

熱門標簽:外呼線路從哪里出來的 天津外呼系統怎么收費 柯城手機地圖如何做地圖標注 AI電銷機器人 線路 巫師3地圖標注魔力之所 征服者企業地圖標注 漯河電銷 中牟外呼系統違法嗎 淮安自動外呼系統供應商
Private
private 函數只能 在本類和子類的 上下文中調用,且只能通過self訪問。

這個意思就是:private函數,只能在本對象內部訪問到。

對象實例變量(@)的訪問權限就是 private。
復制代碼 代碼如下:

class AccessTest
def test
return “test private”
end
def test_other(other)
“other object ”+ other.test
end
end
t1 = AccessTest.new
t2 = AccessTest.new

p t1.test # => test private

p t1.test_other(t2) # => other object test private


# Now make 'test' private

class AccessTest
private :test
end

p t1.test_other(t2) #錯誤 in `test_other': private method `test' called for #AccessTest:0x292c14> (NoMethodError)


Protected
protect 函數只能 在本類和子類的 上下文中調用,但可以使用 other_object.function的形式。(這跟 C++ 的 private 模式等同)

這個的關鍵是 protected函數可以在同類(含子類)的其它對象的內部中使用。

# Now make 'test' protect

class AccessTest
protected:test
end

p t1.test_other(t2) # other object test private

Public
public 函數可以在任何地方調用。成員函數和常量的默認訪問權限就是public。
您可能感興趣的文章:
  • Ruby中的public、private、protected區別小結
  • 簡單談談Ruby的private和protected

標簽:克拉瑪依 甘孜 西雙版納 棗莊 南昌 河池 大慶 內江

巨人網絡通訊聲明:本文標題《Ruby 之 class 中的 private、 protected、public》,本文關鍵詞  Ruby,之,class,中的,private,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Ruby 之 class 中的 private、 protected、public》相關的同類信息!
  • 本頁收集關于Ruby 之 class 中的 private、 protected、public的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 郸城县| 视频| 肥东县| 安图县| 福州市| 邓州市| 定襄县| 许昌市| 崇文区| 鄂伦春自治旗| 东阳市| 鹿邑县| 于都县| 资兴市| 墨竹工卡县| 伊宁县| 乌审旗| 民丰县| 平远县| 乌鲁木齐市| 龙岩市| 天等县| 洪雅县| 鄢陵县| 吉安市| 兴隆县| 通河县| 新郑市| 金沙县| 盐亭县| 五台县| 庆安县| 丹凤县| 宜州市| 习水县| 黎川县| 拜城县| 遂昌县| 招远市| 梨树县| 遵义市|