Parent

Included Modules

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")
  p f1.instance
  f1.instance.update({:name=>'Jerry'})
  p f1.instance

Public Class Methods

new(delegate) click to toggle source
    # File lib/core/facets/kernel/instance.rb, line 33
33:   def initialize(delegate)
34:     @delegate = delegate
35:   end

Public Instance Methods

<<(pair) click to toggle source
    # File lib/core/facets/kernel/instance.rb, line 91
91:   def <<(pair)
92:     name, value = *pair
93:     name = atize(name)
94:     @delegate.instance_variable_set(name, value)
95:   end
[](name) click to toggle source
    # File lib/core/facets/kernel/instance.rb, line 79
79:   def [](name)
80:     name = atize(name)
81:     @delegate.instance_variable_get(name)
82:   end
[]=(name, value) click to toggle source
    # File lib/core/facets/kernel/instance.rb, line 85
85:   def []=(name, value)
86:     name = atize(name)
87:     @delegate.instance_variable_set(name,value)
88:   end
assign(hash) click to toggle source

A hold-over from the the old # method.

Alias for: update
each() click to toggle source
    # File lib/core/facets/kernel/instance.rb, line 43
43:   def each
44:     @delegate.instance_variables.each do |name|
45:       yield(name[1..1].to_sym, @delegate.instance_variable_get(name))
46:     end
47:   end
eval(*a,&b) click to toggle source

Instance evaluation.

     # File lib/core/facets/kernel/instance.rb, line 145
145:   def eval(*a,&b)
146:     @delegate.instance_eval(*a,&b)
147:   end
instance_delegate() click to toggle source
    # File lib/core/facets/kernel/instance.rb, line 38
38:   def instance_delegate
39:     @delegate
40:   end
keys() click to toggle source

Instance vairable names as symbols.

     # File lib/core/facets/kernel/instance.rb, line 124
124:   def keys
125:     @delegate.instance_variables.collect do |name|
126:       name[1..1].to_sym
127:     end
128:   end
names() click to toggle source

Instance variable names as strings.

     # File lib/core/facets/kernel/instance.rb, line 131
131:   def names
132:     @delegate.instance_variables.collect do |name|
133:       name[1..1]
134:     end
135:   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/core/facets/kernel/instance.rb, line 61
61:   def to_h(at=false)
62:     h = {}
63:     if at
64:       @delegate.instance_variables.each do |name|
65:         h[name] = @delegate.instance_variable_get(name)
66:       end
67:     else
68:       each do |key, value|
69:         h[key] = value
70:       end
71:     end
72:     h
73:   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/core/facets/kernel/instance.rb, line 109
109:   def update(hash)
110:     hash.each do |pair|
111:       self << pair
112:     end
113:   end
Also aliased as: assign
values() click to toggle source

Instance variable values.

     # File lib/core/facets/kernel/instance.rb, line 138
138:   def values
139:     @delegate.instance_variables.collect do |name|
140:       @delegate.instance_variable_get(name)
141:     end
142:   end
variables() click to toggle source

Same as #.

     # File lib/core/facets/kernel/instance.rb, line 119
119:   def variables
120:     @delegate.instance_variables
121:   end

Private Instance Methods

atize(name) click to toggle source
     # File lib/core/facets/kernel/instance.rb, line 151
151:     def atize(name)
152:       name.to_s !~ /^@/ ? "@#{name}" : name
153:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.