From: Douglas Seifert Date: 2012-07-03T22:23:36+09:00 Subject: Re: Accessor Methods with a Twist --bcaec52155833e1fe804c3ecd237 Content-Type: text/plain; charset=ISO-8859-1 Maybe the OP is going for something like this: # This module can be mixed in to a class # that has a :name accessor to give it # 'extra' functionality module Named def output_name puts "Name: #{self.name}" end def append_to_name(str) self.name << str end end class Person include Named attr_accessor :name def initialize(name) @name = name end end p = Person.new('Doug') p.output_name p.append_to_name(" Foo") p.output_name The mixin here is silly, but it might give the OP some ideas. In the mixin methods, you can refer to self, which will be an instance of whatever class has mixed in the module. -Doug S On Sun, Jul 1, 2012 at 10:10 AM, Jan E. wrote: > Doug Jolley wrote in post #1066902: > > When Jan said that I hadn't fully grasped the concept of object > > orientation, she wasn't just whistling Dixie. > > I'm actually a "he". ;-) > > > > I know that my understanding has been expanded greatly. > > This > > dialog has been extremely enlightening for me. I need to go play with > > some code now. I have a whole new prospective. Thanks so much to all > > who > > contributed. > > You're welcome. And I can assure you that you're not the only one > struggling with object orientation. This is really a difficult topic. > Even experienced programmers often get it wrong. > > And it's even more difficult to find an appropriate structure for a > program. This is something you need a lot of experience for, you cannot > learn it by reading some books or so. > > So keep it up! :) > > -- > Posted via http://www.ruby-forum.com/. > > --bcaec52155833e1fe804c3ecd237 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Maybe the OP is going for something like this:

# This mo= dule can be mixed in to a class
# that has a :name accessor to gi= ve it
# 'extra' functionality
module Named=
=A0 def output_name
=A0 =A0 puts "Name: #{self.name}"
=A0 end

=
=A0 def append_to_name(str)
=A0 =A0 self.name << str
=A0 end
end

class Person
=
=A0 include Named
=A0 attr_accessor :name
=A0 def = initialize(name)
=A0 =A0 @name =3D name
=A0 end
end

p =3D Person.new('Doug')

p.output_name
p.append_to_name(" Foo")
p.o= utput_name

The mixin here is silly, but it m= ight give the OP some ideas. =A0In the mixin methods, you can refer to self= , which will be an instance of whatever class has mixed in the module.

-Doug S

On Sun, Jul= 1, 2012 at 10:10 AM, Jan E. <lists@ruby-forum.com> wrote= :
Doug Jolley wrote in post #1066902:
> When Jan said that I hadn't fully grasped the co= ncept of object
> orientation, she wasn't just whistling Dixie.

I'm actually a "he". ;-)



I know that my understanding has been expanded greatly.
> This
> dialog has been extremely enlightening for me. =A0I need to go play wi= th
> some code now. =A0I have a whole new prospective. =A0Thanks so much to= all
> who
> contributed.

You're welcome. And I can assure you that you're not the only= one
struggling with object orientation. This is really a difficult topic.
Even experienced programmers often get it wrong.

And it's even more difficult to find an appropriate structure for a
program. This is something you need a lot of experience for, you cannot
learn it by reading some books or so.

So keep it up! :)

--bcaec52155833e1fe804c3ecd237--