Forum: Ruby on Rails indentifier needs to be constant error when calling Struct.n

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.
91d00b2e1d76029cb9175053a846051b?d=identicon&s=25 Michael Johnston (Guest)
on 2007-04-04 18:26
(Received via mailing list)
In my current rails application, I now have the following issue:

script/console
Loading development environment.
 >> bob = Struct.new(:anysymbol)
NameError: identifier anysymbol needs to be constant
         from (irb):1:in `new'
         from (irb):1
 >> exit


This occurs regardless of what symbols are passed to Struct.new call.

Consequently, nothing that uses Struct will work anymore. I
discovered this when attempting to use Fastercsv, which fails when
required.



I'm completely mystified by this error and have little idea how to go
about tracking down what is causing it, short of rebuilding my
application one step at a time. It's fairly big to be doing with at
this point.

What could cause such a problem?

I've made no monkeypatches to Struct. I can't find any code messing
with Struct among the plugins I've installed.


Help.

Michael Johnston
91d00b2e1d76029cb9175053a846051b?d=identicon&s=25 Michael Johnston (Guest)
on 2007-04-04 18:57
(Received via mailing list)
whew. I managed to discover this relatively quickly once I quelled my
panic.

It was caused by an extension called acts_as_wizard, which
monkeypatches Symbol thusly:

class Symbol
...some other monkeycrap^H^H^H^Hpatching
   def to_str
     id2name
   end
end

I'm not entirely sure how this ends up breaking Struct.new, but it
does. It's a lame patch anyway, he should just use id2name or "#
{mysymbol}" instead of making such a patch. Coercions and other such
things that are likely to be pervasively used outside of the code you
are writing are bad bad targets for monkeypatching.

Since the time I installed acts_as_wizard, I have stopped using it
and written my own wizard management code, so luckily I can easily
just pitch this plugin.

Michael Johnston
34684470c122b86613ec8a524b34209b?d=identicon&s=25 Pekka Paal (pege)
on 2007-11-20 13:17
Hey thanks for this info, I've been having the same problems with
net/sftp and net/imap and could not figure out the reason, turned out to
be the act_as_wizard plugin!


Michael Johnston wrote:
> whew. I managed to discover this relatively quickly once I quelled my
> panic.
>
> It was caused by an extension called acts_as_wizard, which
> monkeypatches Symbol thusly:
>
> class Symbol
> ...some other monkeycrap^H^H^H^Hpatching
>    def to_str
>      id2name
>    end
> end
>
> I'm not entirely sure how this ends up breaking Struct.new, but it
> does. It's a lame patch anyway, he should just use id2name or "#
> {mysymbol}" instead of making such a patch. Coercions and other such
> things that are likely to be pervasively used outside of the code you
> are writing are bad bad targets for monkeypatching.
>
> Since the time I installed acts_as_wizard, I have stopped using it
> and written my own wizard management code, so luckily I can easily
> just pitch this plugin.
>
> Michael Johnston
This topic is locked and can not be replied to.