Class: Andromeda::Atom::Region
- Includes:
- Impl::To_S
- Defined in:
- lib/andromeda/atom.rb
Instance Method Summary collapse
- #enter(amount = 1) ⇒ Object
-
#initialize(init_value = 0) ⇒ Region
constructor
A new instance of Region.
- #leave(amount = 1) ⇒ Object
- #to_short_s ⇒ Object
- #value ⇒ Object
- #wait_until_eq(val) ⇒ Object
Methods included from Impl::To_S
Constructor Details
#initialize(init_value = 0) ⇒ Region
Returns a new instance of Region.
55 56 57 58 59 |
# File 'lib/andromeda/atom.rb', line 55 def initialize(init_value = 0) init_value = init_value[:init_value].to_i if init_value.kind_of?(Hash) raise ArgumentError unless init_value.kind_of?(Fixnum) @count = Impl::Atom.new init_value end |
Instance Method Details
#enter(amount = 1) ⇒ Object
65 66 67 68 69 |
# File 'lib/andromeda/atom.rb', line 65 def enter(amount = 1) raise ArgumentError unless amount.kind_of?(Fixnum) raise ArgumentError unless amount >= 0 @count.update { |v| v + amount } end |
#leave(amount = 1) ⇒ Object
71 72 73 74 75 |
# File 'lib/andromeda/atom.rb', line 71 def leave(amount = 1) raise ArgumentError unless amount >= 0 raise ArgumentError unless amount.kind_of?(Fixnum) @count.update { |v| v - amount } end |
#to_short_s ⇒ Object
52 |
# File 'lib/andromeda/atom.rb', line 52 def to_short_s ; "(#{Impl::To_S.short_s(value)})" end |
#value ⇒ Object
63 |
# File 'lib/andromeda/atom.rb', line 63 def value ; @count.value end |
#wait_until_eq(val) ⇒ Object
77 |
# File 'lib/andromeda/atom.rb', line 77 def wait_until_eq(val) ; @count.wait_until_eq(val) end |