Class Instance
In: lib/core/facets/instance.rb
Parent: Object

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

Methods

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

Included Modules

Enumerable

Public Class methods

Public Instance methods

assign(hash)

Alias for update

Instance vairable names as symbols.

Instance variable names as strings.

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 }
to_hash(at=false)

Alias for to_h

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

Same as instance_variables.

[Validate]