A note about classes, instances, and instance variables.
--Class is a blueprint --The instance is an entity --Instance variables are attributes.
To materialize,
--Class is a blueprint of a car --The instance is a real car (for example, Roadster or Silvia) --Instance variables are manufacturer, color, tire type, etc.
A variable defined within an instance method of a class.
Variables that can be used in different instance methods if they are in the same class.
Regular variables can only be used within the same instance method.
The advantage of using instance variables is that you can omit the code to define.
class Bridge
def bridge_height1(height_number)
@height_number = height_number
end
def bridge_height2
@height_number *10
end
end
big_bridge = Bridge.new
puts big_bridge.bridge_height1(3)
puts big_bridge.bridge_height2 #If you don't use instance variables, you'll get an error.
output data:
3
30