This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder