On Jul 13, 12:36 am, Buzz Hill <[email protected]>
wrote:
> class PaymentType < ActiveRecord::Base
>
>   def self.get_payment_types
>     payment_types_all = find(:all, :select => "display_name,
> stored_name" , :order => :display_name)
>     # Creates a nested array of [[display_name,
> stored_name],[display_name, stored_name]]
>     payment_types = payment_types_all.map {|item| [item.display_name,
> item.stored_name]}
>   end
>
>   # must be defined after the method. Can't be defined in a method
>   PAYMENT_TYPES = get_payment_types
>
> end
>
> Here is some code that works fine, but I don't understand the need for
> the self reference in the def, I will get an undefined variable or
> method error.
>

in a nutshell def self.get_payment_types tells ruby to make a class
method (which is basically a single method on the class object, ie
self) rather than an instance method.

Fred
> I don't understand why I need the self when I am inside the class and I
> don't understand if I need the self, why I can't use
> self.get_payment_types
>
> Thanks
> --
> Posted viahttp://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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to