Hi, I''m using 2.0.2. If I add a class to ./lib, the class is created and I can access it on script/console. However, if I extend a (core) class using a file in lib, the class extension does not occur. The methods I want to add do not appear. If I explicitly load the class, the methods get added. But they are not done automatically like with other things in lib. Why? Or, more to the point: What is the correct Rails way to add a method to a core Ruby class? Thanks, Brad -- Bradley Mazurek --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m seeing the same issue. To get around it I require the file directly in config/environment.rb. For example, I have the file ''lib/module.rb'' which looks like this: class Module include ModuleExtensions end For some reason this file is not auto loaded. It also seems to happen with any other class in the core library I try (Integer, etc.). So in my environment.rb: require ''lib/module'' It would be nice to know if there is a nicer (conventional) way to do this. Regards, James On Dec 30 2007, 3:42 pm, "Bradley Mazurek" <bradley.mazu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m using 2.0.2. > > If I add a class to ./lib, the class is created and I can access it on > script/console. > > However, if I extend a (core) class using a file in lib, the class > extension does not occur. The methods I want to add do not appear. > If I explicitly load the class, the methods get added. But they are > not done automatically like with other things in lib. Why? > > Or, more to the point: What is the correct Rails way to add a method > to a core Ruby class? > > Thanks, > Brad > -- > Bradley Mazurek--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
For extending core classes you''ve got the main one right there. One thing to keep in mind is that files are only read out of /lib at startup... that is when you first fire up the console or Rails webserver. If you make changes to the file you''ll have to reload! (in console) or restart the webserver. On Jan 28, 5:04 pm, James Ravn <james.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m seeing the same issue. To get around it I require the file > directly in config/environment.rb. > > For example, I have the file ''lib/module.rb'' which looks like this: > > class Module > include ModuleExtensions > end > > For some reason this file is not auto loaded. It also seems to happen > with any other class in the core library I try (Integer, etc.). > > So in my environment.rb: > > require ''lib/module'' > > It would be nice to know if there is a nicer (conventional) way to do > this. > > Regards, > James > > On Dec 30 2007, 3:42 pm, "Bradley Mazurek" <bradley.mazu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Hi, > > > I''m using 2.0.2. > > > If I add a class to ./lib, the class is created and I can access it on > > script/console. > > > However, if I extend a (core) class using a file in lib, the class > > extension does not occur. The methods I want to add do not appear. > > If I explicitly load the class, the methods get added. But they are > > not done automatically like with other things in lib. Why? > > > Or, more to the point: What is the correct Rails way to add a method > > to a core Ruby class? > > > Thanks, > > Brad > > -- > > Bradley Mazurek--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---