On Mon, Jul 13, 2009 at 6:28 AM, Buzz
Hill<[email protected]> wrote:
> class PaymentType
>
# Inside a class definition self is the class itself
# Note that another equivalent def statement would be
#
# def PaymentType.get_payment_types
#
# since PaymentTime also refers to the class itself.
> def self.get_payment_types
> puts "Master Self is set to: " + self.to_s + " 1"
> puts
> payment_types = ["Check", "Credit Card", "Purchase Order"]
> end
# Now let's define an instance method
def some_method
# self here returns to the object which was sent some_method,
it may refer to different objects at different times.
#
# self.get_payment_types
# will fail here because self refers to an instance of
PaymentType NOT the PaymentType class
#
# PaymentTypes.get_payment_types
# will work, so would
# self.class.get_payment_types
end
> # must be defined after the method. Can't be defined in a method
# Which I hope I just cleared up
#
# Now we are outside of the instance method definition, self once
again refers to the class object
# so this will invoke the class method.
>
> PAYMENT_TYPES = get_payment_types
> end
>
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---