From: "Jesús Gabriel y Galán" Date: 2009-09-06T01:34:20+09:00 Subject: Re: something.new( :attribute => value) thing On Sat, Sep 5, 2009 at 1:29 PM, 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) > 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. As Tim said, Ruby collects key-value pairs at the end of the argument list as a Hash. Here's an example: irb(main):007:0> def test(a,b,c) irb(main):008:1> p [a,b,c] irb(main):009:1> p c.class irb(main):010:1> c.each {|key,value| p [key,value]} irb(main):011:1> end => nil irb(main):012:0> test(1,2,:xxx => 5, :y => 55) [1, 2, {:xxx=>5, :y=>55}] Hash [:xxx, 5] [:y, 55] Jesus.