Sha256: 9d03d2445c1a36a44bdd413e2f34680f140974dc11a342f37a4ef074d65e1041

Contents?: true

Size: 905 Bytes

Versions: 270

Compression:

Stored size: 905 Bytes

Contents

class Object
  # Returns a hash that maps instance variable names without "@" to their
  # corresponding values. Keys are strings both in Ruby 1.8 and 1.9.
  #
  #   class C
  #     def initialize(x, y)
  #       @x, @y = x, y
  #     end
  #   end
  #
  #   C.new(0, 1).instance_values # => {"x" => 0, "y" => 1}
  def instance_values #:nodoc:
    Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] }]
  end

  # Returns an array of instance variable names including "@". They are strings
  # both in Ruby 1.8 and 1.9.
  #
  #   class C
  #     def initialize(x, y)
  #       @x, @y = x, y
  #     end
  #   end
  #
  #   C.new(0, 1).instance_variable_names # => ["@y", "@x"]
  if RUBY_VERSION >= '1.9'
    def instance_variable_names
      instance_variables.map { |var| var.to_s }
    end
  else
    alias_method :instance_variable_names, :instance_variables
  end
end

Version data entries

270 entries across 226 versions & 25 rubygems

Version Path
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/core_ext/object/instance_variables.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/core_ext/object/instance_variables.rb
activesupport-3.2.12 lib/active_support/core_ext/object/instance_variables.rb
activesupport-3.1.11 lib/active_support/core_ext/object/instance_variables.rb
graphael-on-rails-0.5.1 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
graphael-on-rails-0.0.1 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
challah-0.9.1.beta.3 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
devise_sociable-0.1.0 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
backbone-queryparams-rails-0.0.1 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
railscast-assets-0.0.2 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
railscast-assets-0.0.2 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
backbone-deep-rails-0.0.2 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
backbone-deep-rails-0.0.1 vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
challah-0.9.1.beta vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/object/instance_variables.rb
activesupport-3.2.11 lib/active_support/core_ext/object/instance_variables.rb
activesupport-3.1.10 lib/active_support/core_ext/object/instance_variables.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.10/lib/active_support/core_ext/object/instance_variables.rb
challah-0.9.0 vendor/bundle/gems/activesupport-3.2.9/lib/active_support/core_ext/object/instance_variables.rb