@bascule Struct can be anonymous?
Do Ruby Structs actually present any significant advantages over declaring a class and using attr_accessor?
-
-
@bascule Person = Struct.new(:name); Person.new('joe').name -
@joevandyk why are you telling me this? -
@bascule you asked if it had any advantages. It defines#initialize for you, and you can pass in initial values -
@joevandyk ok.@steveklabnik mentioned that too. seems reasonable I guess?
End of conversation
New conversation -
-
-
@bascule no need to make a constructor - End of conversation
New conversation -
-
-
@bascule They give good default implementations of eql? and hash, which is a win for value objects that'll be put in Sets or Hashes.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@bascule structs are lighter weight in terms of memory allocation. attribute access is just offset into an arrayThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@bascule convenience: accessors, initializer, create with splat list. But Struct is like Rails scaffolds IMO, have to ditch eventually -
@joshsusser@bascule I agree. I start with a struct for convenience. Eventually it either becomes a class or dies altogether.
End of conversation
New conversation -
-
-
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.