bcparanj@gmail.com
3/11/2007 10:06:00 PM
Your code works. I want to make the acts_as_chicken :something to be
available only to those ActiveRecord subclasses that uses the
acts_as_chicken declaration. How can I accomplish that?
> >
> > I tried to modify the working example with no luck. Can someone please
> > point me in the right direction?
>
> Don't know anything about plugins, though I suppose
>
> module ClassMethods
> def acts_as_fox(arg)
> do_something(arg)
> class_eval do
> extend Foo::Acts::Fox::SingletonMethods
> end
> include Foo::Acts::Fox::InstanceMethods
> end
> end
Loading development environment.
>> t = Thing.new
=> #<Thing:0x31e3dec @new_record=true, @attributes={"chickens"=>nil}
>> t = Thing.new :chickens => true
=> #<Thing:0x31d7b28 @new_record=true, @attributes={"chickens"=>true}
>> t.catch_chickens
NoMethodError: undefined method `catch_chickens' for #<Thing:
0x31d7b28>
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/
active_record/base.rb:1861:in `method_missing'
from (irb):3
>> Thing.catch_chickens
=> [#<Thing:0x31d3618 @attributes={"id"=>"1", "chickens"=>"1"}]
>> t.eat_chicken
ArgumentError: wrong number of arguments (0 for 1)
from (irb):5:in `eat_chicken'
from (irb):5
>>
?> df
NameError: undefined local variable or method `df' for #<Object:
0x3349ec>
from (irb):7
>> t.eat_chicken(:booie)
Fox with ID just ate a chicken with name booie
=> nil
>> t = Thing.new :chickens => true
=> #<Thing:0x31cb29c @new_record=true, @attributes={"chickens"=>true}
>> t.eat_chicken
ArgumentError: wrong number of arguments (0 for 1)
from (irb):10:in `eat_chicken'
from (irb):10
>> quit
14:07:07:~/work/plugins/fox > script/console
Loading development environment.
>> t = Thing.new :chickens => true
=> #<Thing:0x31e2ac8 @new_record=true, @attributes={"chickens"=>true}
>> t.eat_chicken
NameError: undefined local variable or method `name' for #<Thing:
0x31e2ac8>
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/
active_record/base.rb:1861:in `method_missing'
from ./script/../config/../config/../vendor/plugins/
acts_as_fox/lib/acts_as_fox.rb:36:in `eat_chicken'
from (irb):2
>>
?> k
NameError: undefined local variable or method `k' for #<Object:
0x3349ec>
from (irb):4
17:54:47:~/work/plugins/fox > script/console
Loading development environment.
>> t = Thing.new :chickens => true
good
=> #<Thing:0x31e29b0 @new_record=true, @attributes={"chickens"=>true}
>>