object literal like JavaScript in Ruby

P

petermichaux

Hi,

I've been programming JavaScript a lot lately and would like to find a
way to create and object without defining a class like the JavaScript
object literal. Is there a quick an dirty object in Ruby?

In JavaScript

var a = {foo: 34, bar:89}
a.foo
a.bar


Thanks,
Peter
 
P

Park Heesob

Hi,
Hi,

I've been programming JavaScript a lot lately and would like to find a
way to create and object without defining a class like the JavaScript
object literal. Is there a quick an dirty object in Ruby?

In JavaScript

var a = {foo: 34, bar:89}
a.foo
a.bar

a = Struct.new:)foo,:bar).new(34,89)
a.foo
a.bar
Thanks,
Peter
Regards,
Park Heesob
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top