J
Jason Lillywhite
Could someone help me with this little problem?
I have a file called fruit2.rb which contains:
class Fruit2
def taste
"sweet"
end
end
I want to use this class in a different file called fruit1.rb which
contains:
require "fruit2"
class Fruit1
def color
"red"
end
end
apple = Fruit1.new
p apple.color
apple = Fruit2.new
p apple.taste
I know the way I'm creating my apple object is wrong because I
over-wrote apple when I assigned Fruit2.new. What I want to do is have a
way to call attributes of a single object from different files. In my
application, I have so many methods, I want them in different files, but
want to use them on a single object. Is there an easy way to do this?
--thank you!
I have a file called fruit2.rb which contains:
class Fruit2
def taste
"sweet"
end
end
I want to use this class in a different file called fruit1.rb which
contains:
require "fruit2"
class Fruit1
def color
"red"
end
end
apple = Fruit1.new
p apple.color
apple = Fruit2.new
p apple.taste
I know the way I'm creating my apple object is wrong because I
over-wrote apple when I assigned Fruit2.new. What I want to do is have a
way to call attributes of a single object from different files. In my
application, I have so many methods, I want them in different files, but
want to use them on a single object. Is there an easy way to do this?
--thank you!