5 ms·
Is this supposed to be Ruby? class HotDog: condiments def getCondiments return @condiments // @ is a reference to the curre
by judofyr 17y ago
Is this supposed to be Ruby?
class HotDog:
condiments
def getCondiments
return @condiments // @ is a reference to the current instance of HotDog.
end
end
- jmtulloss 17y agosorry, that was typed up pretty quickly, and I'm not a rubyist... care to correct it?
- jhancock 17y agoclass HotDog @condiments def getCondiments return @condiments // @condiments is an instance variable of an instance of HotDog end end note the mod to both the ivar def and the comment. You also do not need the initial ivar "definition" as ruby defines them on the fly when they are first referenced.
- xtho 17y agoNo, The first @condiments would define a class variable. class HotDog attr_accessor :condiments end Or for Java-socialized folks: class HotDog def initialize @condiments = nil end def getCondiments return @condiments end end
- jhancock 17y agooops, sorry. yes, the first line would define a "class instance" variable. btw, I didn't show the attr_accessor meta-programming sine it hides the guts of the excercise.
- jmtulloss 17y agoI made some corrections. How's it look now?
- jhancock 17y agoI posted a bit too quick and too late at night. See corrections on this thread.