What about {:a => "a", :b => "b"} argument

N

Nicolas Rassat

Hi

I'm doing some gnome/ruby stuff and I wonder how instance method's
argument like {:a => "a", :b => "b"} can be used. Such argument are
used, for example, in Gnome::CanvasLine.new and seems to set instance
variables.

I didn't succeed to use such hash argument. The only way I got is by
using {:mad:a => "a", :mad:b => "b"} with a code like

Class Foo
def set(hash)
hash.each {|k,v| self.instance_variable_set(k,v)}
end
end

Can you explain me how {:a => "a", :b => "b"} should be handled?

Thanks

Nico
 
D

David A. Black

Hi --

Hi

I'm doing some gnome/ruby stuff and I wonder how instance method's argument
like {:a => "a", :b => "b"} can be used. Such argument are used, for example,
in Gnome::CanvasLine.new and seems to set instance variables.

I didn't succeed to use such hash argument. The only way I got is by using
{:mad:a => "a", :mad:b => "b"} with a code like

Class Foo
def set(hash)
hash.each {|k,v| self.instance_variable_set(k,v)}
end
end

Can you explain me how {:a => "a", :b => "b"} should be handled?

instance_variable_set("@#{k}",v)


David
 
N

Nicolas Rassat

David A. Black a écrit :
Hi --

snip

instance_variable_set("@#{k}",v)


David

Ahem... Looks it works

But it's almost 50% more times of computing. So why don't use the :mad:a
syntax (yes in this case it's 50% more times writing... ;-)

Nico
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top