Class: Spruz::Bijection

### Home Classes Methods

### In Files

- lib/spruz/bijection.rb

### Parent

Hash

### Methods

- ::[]
- ::new
- #[]=
- #fill
- #freeze

### 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::Bijection

### Attributes

inverted[R]

### Public Class Methods

[](*pairs) click to toggle source

    # File lib/spruz/bijection.rb, line 3
    def self.[](*pairs)
      pairs.size % 2 == 0 or
        raise ArgumentError, "odd number of arguments for #{self}"
      new.fill do |obj|
        (pairs.size / 2).times do |i|
          j = 2 * i
          key = pairs[j]
          value = pairs[j + 1]
          obj.key?(key) and raise ArgumentError, "duplicate key #{key.inspect} for #{self}"
          obj.inverted.key?(value) and raise ArgumentError, "duplicate value #{value.inspect} for #{self}"
          obj[pairs[j]] = pairs[j + 1]
        end
      end
    end

new(inverted = Bijection.new(self)) click to toggle source

    # File lib/spruz/bijection.rb, line 18
    def initialize(inverted = Bijection.new(self))
      @inverted = inverted
    end

### Public Instance Methods

[]=(key, value) click to toggle source

    # File lib/spruz/bijection.rb, line 38
    def []=(key, value)
      key?(key) and return
      super
      @inverted[value] = key
    end

fill() click to toggle source

    # File lib/spruz/bijection.rb, line 22
    def fill
      if empty?
        yield self
        freeze
      end
      self
    end

freeze() click to toggle source

    # File lib/spruz/bijection.rb, line 30
    def freeze
      r = super
      unless @inverted.frozen?
        @inverted.freeze
      end
      r
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.