yednamus
yednamus

Reputation: 583

can't dump anonymous class Class in ruby

can anyone explain what this exception mean in ruby.

TypeError Exception: can't dump anonymous class Class

Code Sample

   Class X_controller
     before filer: validate, :only => [:meth1]
     def meth1
      y.new.send_later(:issue1) #throws me exception
     end
     def meth2
      y.new.send_later(:issue1) #works
     end
     private
     def valiadate
      y.new.send_later(:issue1) #throws me exception
     end
    end
    class y
     include x::z
     def issue1
     end

    end
    module x::z
     def send_later(meth,*args)
     end
    end

Upvotes: 3

Views: 8392

Answers (1)

alestanis
alestanis

Reputation: 21863

This happens when you try to call to_yaml or to_json or any other representation directly on a class instead of calling it on an instance. For example

User.to_json

will dump, but

user = User.first
user.to_json

will work just fine.

EDIT:

This problem seems to also be a bug in older Rails versions, that was fixed for (at least) Rails 3.

Upvotes: 7

Related Questions