Class | Instance |
In: |
lib/facets/core/facets/instance.rb
|
Parent: | Object |
# File lib/facets/core/facets/instance.rb, line 34 def initialize(delegate) @delegate = delegate end
# File lib/facets/core/facets/instance.rb, line 92 def <<(pair) name, value = *pair name = atize(name) @delegate.instance_variable_set(name, value) end
# File lib/facets/core/facets/instance.rb, line 80 def [](name) name = atize(name) @delegate.instance_variable_get(name) end
# File lib/facets/core/facets/instance.rb, line 86 def []=(name, value) name = atize(name) @delegate.instance_variable_set(name,value) end
# File lib/facets/core/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
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/core/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
Same as instance_variables.
# File lib/facets/core/facets/instance.rb, line 120 def variables @delegate.instance_variables end