<a href="http://ruby-doc.org/stdlib/libdoc/ostruct/rdoc/classes/OpenStruct.html">http://ruby-doc.org/stdlib/libdoc/ostruct/rdoc/classes/OpenStruct.html</a><br>Any good for you?<br><br><div class="gmail_quote">On 10 August 2010 13:08, Daniel Barlow <span dir="ltr"><<a href="mailto:dan@telent.net">dan@telent.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">OK, I'm sure this is one of those things that everyone else knows about except me[*], but Googling is getting me nowhere.<br>

<br>
Is there a gem or a standard idiom for creating Struct-like classes whose #new method accepts named parameters (corresponding to the accessor names) instead of arguments by order?  I would like to write, for example<br>
<br>
 class Book < NamedStruct.new(:isbn,:author,:title,:review_rating)<br>
 b=Book.new(:author=>'Ian McDonald',:title=>'Brasyl')<br>
<br>
 # and in approximately rspec syntax<br>
 b.title.should == Brasyl'<br>
 b.review_rating.should be_nil<br>
<br>
If there isn't then I could probably stand to improve my understanding of Ruby metaprogramming significantly by writing my own, but it seems like the kind of wheel that must have been reinvented many times already, and surely by now someone has made a nice smooth round one<br>

<br>
<br>
<br>
-dan<br>
<br>
[*] like Timecop ... thanks Time & Chris for mentioning it last night<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div><br>