From: Kenichi Kamiya Date: 2012-04-06T04:16:48+09:00 Subject: Re: Call for comments - Structure Hal Fulton wrote in post #1055070: > Greetings, fellow Rubyists... Hi! "The Ruby Way" book is one of my Mentors :) > I am revisiting a small project that has lain dormant for > some time... > > http://github.com/Hal9000/Structure I'm writing a gem too, and i think that likes your project. https://github.com/kachick/striuct > > As I make changes and improvements, I'd be interested in > hearing your comments. My first impression is below. > # to_ary will allow a struct to be treated like an array in > # multiple assignment > myStruct = Structure.new("alpha","beta","gamma") > x = myStruct.new(7,8,9) > a,b,c = x > assert(b == 8) > > # to_ary will allow a struct to be treated like an array in > # passed parameters > myStruct = Structure.new("alpha","beta","gamma") > x = myStruct.new(7,8,9) > b = meth(*x) > > # to_hash will return a hash with fields as keys > myStruct = Structure.new("alpha","beta","gamma") > x = myStruct.new(7,8,9) > h = x.to_hash > assert_equal({"alpha"=>7,"beta"=>8,"gamma"=>9},h) > I guess, this cast method names are expected in some special cases. #to_ary, #to_hash (e.g.: #to_str, #to_int) I recommend below names in our project. #to_a, #to_h, #to_s, #to_i Kenichi -- Posted via http://www.ruby-forum.com/.