J
jtprince
How do I make a custom initializer for a struct object? This is how I would expect it to be accomplished (but this does not work):
Dog = Struct.newbark, :bite) do
def initialize(*args)
super(*args)
bark = "really loud" unless bark
end
end
dd = Dog.new
p dd.bark # => should be "really loud" but is nil
So, structs have no initialize method... I tried some other approaches but no luck yet. Can anyone figure out how to do this?
Dog = Struct.newbark, :bite) do
def initialize(*args)
super(*args)
bark = "really loud" unless bark
end
end
dd = Dog.new
p dd.bark # => should be "really loud" but is nil
So, structs have no initialize method... I tried some other approaches but no luck yet. Can anyone figure out how to do this?