Consider the case when class B would have more member functions.
In your example I would have to create a new object for each call to a
B function.
OTOH, a solution that I dont like could be :
class A
class B
def fun_b
p "B"
end
def other_b
p "_B"
end
end
end
b = A::B.new
b.fun_b
b.other_b
By the instantion of a new B object in the code from the first post,
and refering to it, I was searching to keep a hierarchy inside a
network protocol.
I couldn't find any hint on google though
···
On 11/16/05, Brian Schröder <ruby.brian@gmail.com> wrote:
What problem do you want to solve?
Is this maybe nearer to you goals:
class A
class B
def fun_b
p "B"
end
end
end
A::B.new.fun_b
cheers,
Brian
--
Regards, Groleo!
# Use "Reply to All" on mailing lists.
# touch universe
# chmod +x universe
# ./universe
Maybe you should look at the delegation pattern. That may be
applicable here. But I have not yet understood your use case. Could
you describe it in a bit more detail?
regards,
Brian
···
On 16/11/05, Groleo Marius <groleo@gmail.com> wrote:
On 11/16/05, Brian Schröder <ruby.brian@gmail.com> wrote:
>
> What problem do you want to solve?
>
> Is this maybe nearer to you goals:
>
> class A
> class B
> def fun_b
> p "B"
> end
> end
> end
>
> A::B.new.fun_b
>
> cheers,
>
> Brian
>
Consider the case when class B would have more member functions.
In your example I would have to create a new object for each call to a
B function.
OTOH, a solution that I dont like could be :
class A
class B
def fun_b
p "B"
end
def other_b
p "_B"
end
end
end
b = A::B.new
b.fun_b
b.other_b
By the instantion of a new B object in the code from the first post,
and refering to it, I was searching to keep a hierarchy inside a
network protocol.
I couldn't find any hint on google though
Sure.
Consider a client script that has to querry a server.
The server operate on users/domains of a running qmail.
So, I would have a class named Client, with the folowing members:
login( user, pass ) logins to the remote administration server
domain an instantion of a domain class.
OTOH Domain class has X member functions:
add( domain_name) adds a new domain
remove
update
So a scenario would look like:
c =Client.new #creates a new Domain object
c.login( "foo", "bar" )
c.domain.add( "localdomain" )
Now , back to the code ,the attr_reader was the magic word from what
Pit posted .
Maybe you too observed, but why in ruby
this attr_reader : b is different from attr_reader :b
^space ^no space
···
On 11/16/05, Brian Schröder <ruby.brian@gmail.com> wrote:
On 16/11/05, Groleo Marius <groleo@gmail.com> wrote:
> On 11/16/05, Brian Schröder <ruby.brian@gmail.com> wrote:
> >
> > What problem do you want to solve?
> >
> > Is this maybe nearer to you goals:
> >
> > class A
> > class B
> > def fun_b
> > p "B"
> > end
> > end
> > end
> >
> > A::B.new.fun_b
> >
> > cheers,
> >
> > Brian
> >
>
> Consider the case when class B would have more member functions.
> In your example I would have to create a new object for each call to a
> B function.
> OTOH, a solution that I dont like could be :
> class A
> class B
> def fun_b
> p "B"
> end
> def other_b
> p "_B"
> end
> end
> end
> b = A::B.new
> b.fun_b
> b.other_b
>
> By the instantion of a new B object in the code from the first post,
> and refering to it, I was searching to keep a hierarchy inside a
> network protocol.
> I couldn't find any hint on google though
>
Maybe you should look at the delegation pattern. That may be
applicable here. But I have not yet understood your use case. Could
you describe it in a bit more detail?
--
Regards, Groleo!
# Use "Reply to All" on mailing lists.
# touch universe
# chmod +x universe
# ./universe
Because :b is the symbol :b while : b is a colon followed by a b which
is not allowed syntax here.
cheers,
Brian
···
On 16/11/05, Groleo Marius <groleo@gmail.com> wrote:
On 11/16/05, Brian Schröder <ruby.brian@gmail.com> wrote:
> On 16/11/05, Groleo Marius <groleo@gmail.com> wrote:
> > On 11/16/05, Brian Schröder <ruby.brian@gmail.com> wrote:
> > >
> > > What problem do you want to solve?
> > >
> > > Is this maybe nearer to you goals:
> > >
> > > class A
> > > class B
> > > def fun_b
> > > p "B"
> > > end
> > > end
> > > end
> > >
> > > A::B.new.fun_b
> > >
> > > cheers,
> > >
> > > Brian
> > >
> >
> > Consider the case when class B would have more member functions.
> > In your example I would have to create a new object for each call to a
> > B function.
> > OTOH, a solution that I dont like could be :
> > class A
> > class B
> > def fun_b
> > p "B"
> > end
> > def other_b
> > p "_B"
> > end
> > end
> > end
> > b = A::B.new
> > b.fun_b
> > b.other_b
> >
> > By the instantion of a new B object in the code from the first post,
> > and refering to it, I was searching to keep a hierarchy inside a
> > network protocol.
> > I couldn't find any hint on google though
> >
>
> Maybe you should look at the delegation pattern. That may be
> applicable here. But I have not yet understood your use case. Could
> you describe it in a bit more detail?
Sure.
Consider a client script that has to querry a server.
The server operate on users/domains of a running qmail.
So, I would have a class named Client, with the folowing members:
login( user, pass ) logins to the remote administration server
domain an instantion of a domain class.
OTOH Domain class has X member functions:
add( domain_name) adds a new domain
remove
update
So a scenario would look like:
c =Client.new #creates a new Domain object
c.login( "foo", "bar" )
c.domain.add( "localdomain" )
Now , back to the code ,the attr_reader was the magic word from what
Pit posted .
Maybe you too observed, but why in ruby
this attr_reader : b is different from attr_reader :b
^space ^no space
Now , back to the code ,the attr_reader was the magic word from what
Pit posted .
Maybe you too observed, but why in ruby
this attr_reader : b is different from attr_reader :b
^space ^no space
Because colon-identifier represents a symbol, and attr_reader takes
symbols as arguments. The colon is not a separator. For example:]