Mega Code Archive

 
Categories / Ruby / Class
 

Creating Readable and Writable Attributes

class Animal   attr_accessor :color   def initialize(color)     @color = color   end end animal = Animal.new("brown") puts "The new animal is " + animal.color animal.color = "red" puts "Now the new animal is " + animal.color