Sha256: 64b93a66afe712a9eb03a4aac56acb71a119a9c2345f827532d173a0bb6932cf

Contents?: true

Size: 842 Bytes

Versions: 14

Compression:

Stored size: 842 Bytes

Contents

module Kernel

  # Return instance variable values in an array.
  #
  #   class X
  #     def initialize(a,b)
  #       @a, @b = a, b
  #     end
  #   end
  #
  #   x = X.new(1,2)
  #
  #   x.instance_values   #=> { "a"=>1, "b"=>2 }
  #
  # WARNING: #instance_values will be deprecated. Use instance_vars.to_hash instead.

  def instance_values
    instance_variables.inject({}) do |values, name|
      values[name[1..-1]] = instance_variable_get(name)
      values
    end
  end

  # Set instance variables using a hash.
  #
  #   instance_assign('@a'=>1, '@b'=>2)
  #   @a   #=> 1
  #   @b   #=> 2
  #
  # WARNING: #instance_assign will be deprecated. Use instance_vars.update instead.

  def instance_assign(hash)
    hash.each do |k,v|
      k = "@#{k}" if k !~ /^@/
      instance_variable_set(k, v)
    end
    return self
  end

end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
facets-2.8.2 lib/core/facets/kernel/instance_assign.rb
facets-2.8.1 lib/core/facets/kernel/instance_assign.rb
facets-2.8.0 lib/core/facets/kernel/instance_assign.rb
facets-2.7.0 lib/core/facets/kernel/instance_assign.rb
facets-2.6.0 lib/core/facets/kernel/instance_assign.rb
facets-2.4.1 lib/facets/kernel/instance_assign.rb
facets-2.4.4 lib/core/facets/kernel/instance_assign.rb
facets-2.4.3 lib/core/facets/kernel/instance_assign.rb
facets-2.4.2 lib/core/facets/kernel/instance_assign.rb
facets-2.5.0 lib/core/facets/kernel/instance_assign.rb
facets-2.4.5 lib/core/facets/kernel/instance_assign.rb
facets-2.5.1 lib/core/facets/kernel/instance_assign.rb
facets-2.5.2 lib/core/facets/kernel/instance_assign.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_assign.rb