class InstanceVariables
Public Class Methods
new(delegate)
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 14 def initialize(delegate) @delegate = delegate end
Public Instance Methods
<<(pair)
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 46 def <<(pair) name, value = *pair name = atize(name) @delegate.instance_variable_set(name, value) end
[](name)
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 36 def [](name) name = atize(name) @delegate.instance_variable_get(name) end
[]=(name, value)
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 41 def []=(name, value) name = atize(name) @delegate.instance_variable_set(name,value) end
each() { |to_sym, instance_variable_get| ... }
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 22 def each @delegate.instance_variables.each do |name| yield(name[1..-1].to_sym, @delegate.instance_variable_get(name)) end end
instance_delegate()
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 18 def instance_delegate @delegate end
keys()
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 59 def keys @delegate.instance_variables.collect do |name| name[1..-1].to_sym end end
names()
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 65 def names @delegate.instance_variables.collect do |name| name[1..-1] end end
to_hash()
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 28 def to_hash h = {} each do |name, value| h[name] = value end h end
update(hash)
click to toggle source
(See also: Kernel#populate, which uses accessor method rather than setting instance variables directly.)
# File lib/core/facets/kernel/instance_variables.rb, line 53 def update(hash) hash.each do |pair| self << pair end end
values()
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 71 def values @delegate.instance_variables.collect do |name| @delegate.instance_variable_get(name) end end
Private Instance Methods
atize(name)
click to toggle source
# File lib/core/facets/kernel/instance_variables.rb, line 79 def atize(name) name !~ /^@/ ? "@#{name}" : name end