Skip to content

Instantly share code, notes, and snippets.

class Work
attr_accessor :name, :duration
def intialize(name, duration)
@name, @duration = name, duration
end
end
job = Work.new("ROR learning", "1month")
job.name
=> "ROR learning"
job.duration
class Work
def initialize(name) #when instance object created, the object calls the inititalize method and initiated the valur to instance variables
@name = name
end
def duration=(time)
@duration = time
end
def duration
@duration
end
class Work
def name=(name) #which works like a setter method of class
@name = name
end
def name #which works like a gettter method, gets the name from current object scope
@name
end
end
job = Work.new #which creates the new instance object