To add to the current answers, @instance_variables
from object-oriented programming ...
object-oriented programming
, instance variable
- , (.. -), .
OOP
"" - strings
, integers
.. .
() ( classes
). , , , ...
class Product < ActiveRecord::Base
end
def new
@product = Product.new
end
Ruby/Rails ; , . : :

- / ( Product
), .
, . , :
@product = Product.new
@product.save
-
class
:
class ProductsController < ApplicationController
def show
@product = Product.new
end
end
Rails classes
, :
Request > Rack > Routes > ProductsController.new(request).show > Response
, @instance_variable
, instance
...
class ProductsController < ApplicationController
def show
@product = Product.new
product_save
end
private
def product_save
@product.save
end
end
@instance_variables
/ , . ( Product
) stock
:
class Product < ActiveRecord::Base
def stock
@qty / @orders
end
end
getter/setter
Ruby, , :
@product = Product.find x
@product.stock