Module: Spruz::Once

### Home Classes Methods

### In Files

- lib/spruz/once.rb

### Methods

- #only_once
- #try_only_once

### Included Modules

- File::Constants

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Spruz
- Spruz::Attempt
- Spruz::Bijection
- Spruz::Blank
- Spruz::Blank::Array
- Spruz::Blank::FalseClass
- Spruz::Blank::Hash
- Spruz::Blank::NilClass
- Spruz::Blank::Numeric
- Spruz::Blank::Object
- Spruz::Blank::String
- Spruz::Blank::TrueClass
- Spruz::CountBy
- Spruz::DeepDup
- Spruz::FileBinary
- Spruz::FileBinary::ClassMethods
- Spruz::FileBinary::Constants
- Spruz::Full
- Spruz::GO
- Spruz::Generator
- Spruz::HashSymbolizeKeysRecursive
- Spruz::HashUnion
- Spruz::Limited
- Spruz::LinesFile
- Spruz::LinesFile::LineExtension
- Spruz::Memoize
- Spruz::Minimize
- Spruz::ModuleGroup
- Spruz::Null
- Spruz::Once
- Spruz::P
- Spruz::PartialApplication
- Spruz::RangePlus
- Spruz::Round
- Spruz::SecureWrite
- Spruz::Shuffle
- Spruz::StringCamelize
- Spruz::StringUnderscore
- Spruz::StringVersion
- Spruz::StringVersion::Version
- Spruz::Subhash
- Spruz::TimeDummy
- Spruz::TimeDummy::ClassMethods
- Spruz::ToProc
- Spruz::UniqBy
- Spruz::Write
- Array
- Enumerable
- File
- Float
- Hash
- IO
- IRB
- Integer
- Method
- Module
- Object
- Proc
- Range
- String
- Symbol
- Time

No matching classes.

# Spruz::Once

### Public Instance Methods

only_once(lock_filename = nil, locking_constant = nil) click to toggle source

    # File lib/spruz/once.rb, line 7
    def only_once(lock_filename = nil, locking_constant = nil)
      lock_filename ||= $0
      locking_constant ||= LOCK_EX
      f = File.new(lock_filename, RDONLY)
      f.flock(locking_constant) and yield
    ensure
      if f
        f.flock LOCK_UN
        f.close
      end
    end

try_only_once(lock_filename = nil, locking_constant = nil, &block) click to toggle source

    # File lib/spruz/once.rb, line 19
    def try_only_once(lock_filename = nil, locking_constant = nil, &block)
      only_once(lock_filename, locking_constant || LOCK_EX | LOCK_NB, &block)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.