From: Robert Klemme Date: 2004-09-28T21:19:22+09:00 Subject: Re: Best name for "this method" ? "trans. (T. Onoma)" schrieb im Newsbeitrag news:200409280805.07778.transami@runbox.com... > On Tuesday 28 September 2004 05:44 am, Gavin Sinclair wrote: > > There are two possible factorings. Have Object#methods return a > > specialised object, thus: > > > > foo.methods.private > > foo.methods.all > > foo.methods.new > > foo.methods.singleton > > foo.methods[:new, :protected] # if you need combination > > # etc. > > For this approach, I think combinations would be better like: > > foo.methods { |m| m.private | m.singleton } > foo.methods { |m| m.private + m.public } > > But I think it might be a bit much to have a whole new class for this. > > Sometimes I really wish symbolic keyed hashes were accessable like object > methods: > > h = { a: 1, b: 2 } > h.a #=> 1 > h.b #=> 2 You mean like this: >> s=SymHash.new.update( :a=>2, :b=>3 ) => {:a=>2, :b=>3} >> s.a => 2 >> s.c => nil >> s.b => 3 >> s.c=100 => 100 >> s => {:a=>2, :b=>3, :c=>100} class SymHash < Hash def method_missing(sym,*args) key = sym.to_s.sub!(/=$/, '') if key self[key.to_sym]=args[0] else self[sym] end end end > That would be sweet. And would make the above possible without a new class. I > know, method name clash is bad --and there's little one can do to get around > it. Perhaps alternate notation? I'd rather not have another separator - "." and "::" is enough IMHO. > h:a > h:b > > But I digress. I guess so. :-) But sometimes good ideas come from this. Regards robert