1

In Ruby 1.8.6, I could write class PerformableMethod < Struct.new(:object, :method, :args)

Now in Ruby 1.9.3, that throws an error: superclass mismatch for class PerformableMethod

It works if I change the code to:

class PerformableMethod
    attr_accessor :object, :method_name, :args

But why doesn't the struct work?

4

2 に答える 2

0

While typing out this question, my colleague sitting right next to me figured it out.

Struct now takes the class name as its first parameter.

So in Ruby 1.9.3 the following works:

class << Struct.new('PerformableMethod', :object, :method, :args)
于 2012-05-25T17:49:59.567 に答える