Forum: Ruby on Rails Version of Struct for initializing via Hash

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Eric G. (Guest)
on 2009-03-16 22:57
is there any equivalent to this

class A

attr_accessor :foo, :bar

def initialize(options={})
options.each{|k,v| send("#{k}=", v)}


I know that OpenStruct is very similar, but you don't get to define
specific attributes.
This topic is locked and can not be replied to.