[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How do I create an attribute accessor to do this...

J2M

9/24/2006 10:06:00 PM

I want to be able to do this to merge a hash into attribute bas on
instance bar in class foo;

bar = Foo.new
bar.bas << { :this => "that" }

Is there any way to define the accessor in Foo to be able to do this?

Thanks,
James


5 Answers

Trans

9/24/2006 10:20:00 PM

0


J2M wrote:
> I want to be able to do this to merge a hash into attribute bas on
> instance bar in class foo;
>
> bar = Foo.new
> bar.bas << { :this => "that" }
>
> Is there any way to define the accessor in Foo to be able to do this?
>
> Thanks,
> James

class Hash
alias :<<, :merge!
end

class Foo
attr :bas
def initialize
@bas = {}
end
end

Is that what you had in mind?

T.

dblack

9/24/2006 10:21:00 PM

0

J2M

9/24/2006 11:02:00 PM

0

Thanks Trans, I will have a go tomorrow it is very late here in the UK
:)


J2M

9/24/2006 11:04:00 PM

0

Thanks Trans, I will have a go tomorrow it is very late here in the UK
:)


J2M

9/24/2006 11:06:00 PM

0

Thank you both for such quick responses. I will give this a go tomorrow
(v. late here in the UK).

David - thank you for all the time you take to help out us newbies, and
thank you for RailsConf Europe too - fan-tas-tic!