G
Giles Bowkett
is there an easy, elegant way to set up a Struct so it has defaults on
initialization?
(besides def initialize?)
initialization?
(besides def initialize?)
is there an easy, elegant way to set up a Struct so it has defaults on
initialization?
(besides def initialize?)
Not an exact answer to your question, but would using OpenStruct fit the
bill?
#!/usr/bin/env ruby
require 'ostruct'
user = OpenStruct.new({:name => 'Bob', :uid => 1234})
p user.name
p user.uid
user.name = 'Fred'
p user.name
is there an easy, elegant way to set up a Struct so it has defaults on
initialization?
(besides def initialize?)
Hi,
At Fri, 17 Nov 2006 03:30:40 +0900,
Giles Bowkett wrote in [ruby-talk:225339]:is there an easy, elegant way to set up a Struct so it has defaults on
initialization?
(besides def initialize?)
class User < Struct.newname, :uid)
def initialize(name = 'Bob', uid = 1234)
super
end
end
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.