Greetings. I''ve got very strange behavior of alias_method_chains, and I hope someone will advise me. I have a rails 2.2.2 app created with #rails aliasApp , a class XYZ residing in app/helpers/xyz.rb: <code> class XYZ attr_accessor :name attr_accessor :value def initialize (a, b) puts "in XYZ constructor" self.name = a self.value = b end def a puts self.name end def b puts self.value end end </code> , and an extended class XYZ in app/views/xyz_ext.rb <code> class XYZ def initialize_with_extension a,b puts "before chain" initialize_without_extension a,b puts "after chain" end alias_method_chain :initialize, :extension end </code> So basically what I expect to have three lines in the console when creating XYZ: 1) before chain 2) in Alias constructor 3) after chain BUT I get something really different! silencio:alias u2$ script/console Loading development environment (Rails 2.2.2)>> require ''app/views/xyz_ext.rb''=> ["XYZ"]>> XYZ.new 1,3before chain ArgumentError: wrong number of arguments (2 for 0) from ./app/views/xyz_ext.rb:4:in `initialize_without_extension'' from ./app/views/xyz_ext.rb:4:in `initialize'' from (irb):3:in `new'' from (irb):3>>Any ideas on this error would be very appreciated! Alex -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The problem here is that the "normal" XYZ in xyz.rb is never loaded so you''re trying to call Object''s initialize, which does not take 2 arguments Fred Sent from my iPhone On 23 Nov 2008, at 18:52, Alex Sonar <rails-mailing-list@andreas- s.net> wrote:> > Greetings. > > I''ve got very strange behavior of alias_method_chains, and I hope > someone will advise me. > > I have a rails 2.2.2 app created with > #rails aliasApp > > , a class XYZ residing in app/helpers/xyz.rb: > > <code> > class XYZ > > attr_accessor :name > attr_accessor :value > > def initialize (a, b) > puts "in XYZ constructor" > self.name = a > self.value = b > end > > def a > puts self.name > end > > def b > puts self.value > end > end > </code> > > , and an extended class XYZ in app/views/xyz_ext.rb > > <code> > class XYZ > def initialize_with_extension a,b > puts "before chain" > initialize_without_extension a,b > puts "after chain" > end > alias_method_chain :initialize, :extension > end > </code> > > So basically what I expect to have three lines in the console when > creating XYZ: > 1) before chain > 2) in Alias constructor > 3) after chain > > BUT I get something really different! > > silencio:alias u2$ script/console > Loading development environment (Rails 2.2.2) >>> require ''app/views/xyz_ext.rb'' > => ["XYZ"] >>> XYZ.new 1,3 > before chain > ArgumentError: wrong number of arguments (2 for 0) > from ./app/views/xyz_ext.rb:4:in `initialize_without_extension'' > from ./app/views/xyz_ext.rb:4:in `initialize'' > from (irb):3:in `new'' > from (irb):3 >>> > > Any ideas on this error would be very appreciated! > Alex > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Fred, I really appreciate your help. The following works like a charm. silencio:alias u2$ script/console Loading development environment (Rails 2.2.2)>> require ''app/helpers/alias.rb''=> ["XYZ"]>> require ''app/views/alias_ext.rb''=> []>> XYZ.new 1,2before chain in Alias constructor after chain => #<XYZ:0x259c73c @value=2, @name=1> But having this in mind, how do I ensure that my ''app/helpers/alias.rb'' is loaded BEFORE any extended classes? Sorry if this a really newbie question.. Alex Frederick Cheung wrote:> The problem here is that the "normal" XYZ in xyz.rb is never loaded so > you''re trying to call Object''s initialize, which does not take 2 > arguments > > Fred > > Sent from my iPhone > > On 23 Nov 2008, at 18:52, Alex Sonar <rails-mailing-list@andreas--- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Require it explicitly from the extension file ? Sent from my iPhone On 23 Nov 2008, at 20:31, Alex Sonar <rails-mailing-list@andreas- s.net> wrote:> > Fred, > > I really appreciate your help. The following works like a charm. > > silencio:alias u2$ script/console > Loading development environment (Rails 2.2.2) >>> require ''app/helpers/alias.rb'' > => ["XYZ"] >>> require ''app/views/alias_ext.rb'' > => [] >>> XYZ.new 1,2 > before chain > in Alias constructor > after chain > => #<XYZ:0x259c73c @value=2, @name=1> > > But having this in mind, how do I ensure that my ''app/helpers/ > alias.rb'' > is loaded BEFORE any extended classes? Sorry if this a really newbie > question.. > > Alex > > > Frederick Cheung wrote: >> The problem here is that the "normal" XYZ in xyz.rb is never loaded >> so >> you''re trying to call Object''s initialize, which does not take 2 >> arguments >> >> Fred >> >> Sent from my iPhone >> >> On 23 Nov 2008, at 18:52, Alex Sonar <rails-mailing-list@andreas- > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks again! Frederick Cheung wrote:> Require it explicitly from the extension file ? > > Sent from my iPhone > > On 23 Nov 2008, at 20:31, Alex Sonar <rails-mailing-list@andreas--- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---