From: Tim Hunter Date: 2009-09-05T20:51:21+09:00 Subject: Re: something.new( :attribute => value) thing Marc-antoine Kruzik wrote: > Hello, I saw something very interesting in the code of FXRuby, and I > would like to use this kind of code in my scripts : > > My_Window.new(app, "Button Test", :opts => DECOR_ALL, :x => 100, :y => > 100) > > > I'm only able to do "classic" initialisations, such as : > My_Window.new(app, "Button Test", DECOR_ALL, 100, 100) > > > > What is the easiest way to create class which use the ":opts => ... x => > ... y => " part ? > I'm sorry, I don't know the name of this feature, so it's quite > difficult to find informations about it. When the trailing method arguments are key => value pairs, Ruby collects them into a hash and passes the hash as the last argument to the method. Frequently the keys are symbols such as :opts or :x. The keys don't have to be symbols, though. See http://www.softiesonrails.com/2007/8/27/ruby-101-hashes-are-cool -- MagickWand for Ruby - http://magickwand.rubyforge.org/