You can access and modify an object's instance variables using instance_variable_get and instance_variable_set method.

Example:

class C
  def initialize
    self.x = 2
  end

  private
  attr_accessor :x
end

c = C.new

#NoMethodError: private methods `x` and `x=`called
c.x = 4
puts c.x

#But this is alright
c.instance_variable_set :@x, 4
puts c.instance_variable_get :@x # => 4