本文簡要介紹ruby語言中 Mutex_m模塊
的用法。
mutex_m.rb
當需要‘mutex_m’ 時,任何擴展或包含 Mutex_m
的對象都將被視為互斥體。
首先要求標準庫 Mutex_m
:
require "mutex_m.rb"
從這裏您可以使用 Mutex 實例方法擴展對象:
obj = Object.new
obj.extend Mutex_m
或者將 Mutex_m
混合到你的模塊中,讓你的類繼承互斥體實例方法——記得在你的類初始化方法中調用super()。
class Foo
include Mutex_m
def initialize
# ...
super()
end
# ...
end
obj = Foo.new
# this obj can be handled like Mutex
相關用法
- Ruby Mutex類用法及代碼示例
- Ruby MatchData.pre_match用法及代碼示例
- Ruby Matrix lup()用法及代碼示例
- Ruby Matrix unitary?()用法及代碼示例
- Ruby Matrix symmetric?()用法及代碼示例
- Ruby Matrix t()用法及代碼示例
- Ruby Matrix identity()用法及代碼示例
- Ruby Matrix hash()用法及代碼示例
- Ruby Method.owner用法及代碼示例
- Ruby Module.attr_accessor用法及代碼示例
- Ruby Matrix hadamard_product()用法及代碼示例
- Ruby Matrix singular?()用法及代碼示例
- Ruby Module.method_removed用法及代碼示例
- Ruby Math sqrt()用法及代碼示例
- Ruby Matrix round()用法及代碼示例
- Ruby Method.inspect用法及代碼示例
- Ruby Matrix collect()用法及代碼示例
- Ruby Math.acosh用法及代碼示例
- Ruby Module.private用法及代碼示例
- Ruby Markdown類用法及代碼示例
- Ruby Matrix hermitian?()用法及代碼示例
- Ruby Matrix row_vectors()用法及代碼示例
- Ruby Matrix conjugate()用法及代碼示例
- Ruby Method.to_s用法及代碼示例
- Ruby Math.asinh用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Mutex_m模塊。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。