Forum: Ruby Spreadsheet development

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ahmed A. (Guest)
on 2009-04-22 02:30
Hi,...

I'd like to create a Spreadsheet model, where I can access cells like
the following:

sheet = Spreadsheet.new
sheet.cells.a1 = 'Hello'
sheet.cells.b3 = 'World'

The problem is in how to define cell names to be accessed in the above
manner?

Any help?

Thanks

Ahmed
Martin DeMello (Guest)
on 2009-04-22 02:37
(Received via mailing list)
On Wed, Apr 22, 2009 at 4:00 AM, Ahmed A. <removed_email_address@domain.invalid>
wrote:
> manner?
>
> Any help?

method_missing should do it

irb(main):001:0> class Cells
irb(main):002:1>   def method_missing(meth, *args)
irb(main):003:2>     print "you tried to access cell #{meth}"
irb(main):004:2>   end
irb(main):005:1> end
irb(main):006:0> cells = Cells.new
irb(main):007:0> cells.a1
you tried to access cell a1

martin
Ahmed A. (Guest)
on 2009-04-22 15:36
Martin DeMello wrote:
> On Wed, Apr 22, 2009 at 4:00 AM, Ahmed A. <removed_email_address@domain.invalid>
> wrote:
>> manner?
>>
>> Any help?
>
> method_missing should do it
>
> irb(main):001:0> class Cells
> irb(main):002:1>   def method_missing(meth, *args)
> irb(main):003:2>     print "you tried to access cell #{meth}"
> irb(main):004:2>   end
> irb(main):005:1> end
> irb(main):006:0> cells = Cells.new
> irb(main):007:0> cells.a1
> you tried to access cell a1
>
> martin

Thanks martin for your response. I've tried it with ruby and it's OK.
Actually my objective is to run it with JRuby, but the same code is
giving error:
at (unknown).(unknown)(Unknown Source)
  at #<Class:01x114025>.method_missing(<unknown>:1)
  at (unknown).(unknown)(:1)

Any suggestion?

Regards,..

Ahmed
Mark T. (Guest)
on 2009-04-22 16:20
(Received via mailing list)
> Thanks martin for your response. I've tried it with ruby and it's OK.
> Actually my objective is to run it with JRuby, but the same code is
> giving error:
> at (unknown).(unknown)(Unknown Source)
>   at #<Class:01x114025>.method_missing(<unknown>:1)
>   at (unknown).(unknown)(:1)
>
> Any suggestion?

Upgrade? There were problems with method_missing in older versions of
JRuby. I don't know what version you're using, but I would suggest
1.2.

-- Mark.
This topic is locked and can not be replied to.