### Home Classes Methods

### In Files

- lib/facets/instance.rb

### Parent

Object

### Methods

- ::new
- #<<
- #[]
- #[]=
- #assign
- #atize
- #each
- #eval
- #instance_delegate
- #keys
- #names
- #to_h
- #to_hash
- #update
- #values
- #variables

### Included Modules

- Enumerable

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Lazy
- Lazy::Future
- Lazy::Promise
- Lazy::Promise::DIVERGES
- Lazy::PromiseSafe
- Enumerable
- Enumerable::Recursor
- Method
- Method::Composition
- Module
- Module::InstanceFunction
- Array
- Binding
- Class
- Comparable
- Denumerable
- Denumerator
- Dir
- Enumerator
- Exception
- Facets
- FalseClass
- File
- FileTest
- Fixnum
- Float
- Functor
- Hash
- Indexable
- Instance
- Integer
- Kernel
- MatchData
- NA
- NilClass
- Numeric
- Object
- ObjectSpace
- Proc
- Process
- Range
- Regexp
- String
- Struct
- Symbol
- Time
- TrueClass
- UnboundMethod

No matching classes.

# Instance

# Instance Class

    class Friend
      attr_accessor :name, :age, :phone
      def initialize(name, age, phone)
        @name, @age, @phone = name, age, phone
      end
    end

    f1 = Friend.new("John", 30, "555-1212")
    f1.instance

    f1.instance.update({:name=>'Jerry'})
    f1.instance

### Public Class Methods

new(delegate) click to toggle source

    # File lib/facets/instance.rb, line 34
    def initialize(delegate)
      @delegate = delegate
    end

### Public Instance Methods

<<(pair) click to toggle source

    # File lib/facets/instance.rb, line 92
    def <<(pair)
      name, value = *pair
      name = atize(name)
      @delegate.instance_variable_set(name, value)
    end

[](name) click to toggle source

    # File lib/facets/instance.rb, line 80
    def [](name)
      name = atize(name)
      @delegate.instance_variable_get(name)
    end

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

    # File lib/facets/instance.rb, line 86
    def []=(name, value)
      name = atize(name)
      @delegate.instance_variable_set(name,value)
    end

assign(hash) click to toggle source

A hold-over from the the old instance_assign method.

Alias for: update
each() click to toggle source

    # File lib/facets/instance.rb, line 44
    def each
      @delegate.instance_variables.each do |name|
        yield(name[1..-1].to_sym, @delegate.instance_variable_get(name))
      end
    end

eval(*a,&b) click to toggle source

Instance evaluation.

    # File lib/facets/instance.rb, line 146
    def eval(*a,&b)
      @delegate.instance_eval(*a,&b)
    end

instance_delegate() click to toggle source

    # File lib/facets/instance.rb, line 39
    def instance_delegate
      @delegate
    end

keys() click to toggle source

Instance vairable names as symbols.

    # File lib/facets/instance.rb, line 125
    def keys
      @delegate.instance_variables.collect do |name|
        name[1..-1].to_sym
      end
    end

names() click to toggle source

Instance variable names as strings.

    # File lib/facets/instance.rb, line 132
    def names
      @delegate.instance_variables.collect do |name|
        name[1..-1]
      end
    end

to_h(at=false) click to toggle source

Return instance variables with values as a hash.

    class X
      def initialize(a,b)
        @a, @b = a, b
      end
    end

    x = X.new(1,2)

    x.instance.to_h  #=> { :a=>1, :b=>2 }

    # File lib/facets/instance.rb, line 62
    def to_h(at=false)
      h = {}
      if at
        @delegate.instance_variables.each do |name|
          h[name] = @delegate.instance_variable_get(name)
        end
      else
        each do |key, value|
          h[key] = value
        end
      end
      h
    end

Also aliased as: to_hash
to_hash(at=false) click to toggle source

TODO: Not sure if this should be used.

Alias for: to_h
update(hash) click to toggle source

Set instance variables given a `hash`.

    instance.update('@a'=>1, '@b'=>2)
    @a   #=> 1
    @b   #=> 2

Also, +@+ sign is not neccessary.

    instance.update(:a=>1, :b=>2)
    @a   #=> 1
    @b   #=> 2

    # File lib/facets/instance.rb, line 110
    def update(hash)
      hash.each do |pair|
        self << pair
      end
    end

Also aliased as: assign
values() click to toggle source

Instance variable values.

    # File lib/facets/instance.rb, line 139
    def values
      @delegate.instance_variables.collect do |name|
        @delegate.instance_variable_get(name)
      end
    end

variables() click to toggle source

Same as instance_variables.

    # File lib/facets/instance.rb, line 120
    def variables
      @delegate.instance_variables
    end

### Private Instance Methods

atize(name) click to toggle source

    # File lib/facets/instance.rb, line 152
    def atize(name)
      name.to_s !~ /^@/ ? "@#{name}" : name
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.