[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Same class, different module

Caleb Tennis

12/14/2005 9:05:00 PM

Here's a small snippet of code I'm trying to hack on:

module Mod1
class A
def meth
puts "in Mod 1"
end
end

class B
def initialize
A.new.meth
end
end
end

module Mod2
class A < Mod1::A
def meth
put "in Mod 2"
end
end

class B < Mod1::B
end
end

p Mod1::B.new
p Mod2::B.new



caleb@tcdevel ~ $ ruby testit.rb
in Mod 1
#<Mod1::B:0xb7c888dc>
in Mod 1
#<Mod2::B:0xb7c88508>

What I'm trying to accomplish is having B reference A but in the same module
its currently in. I can accomplish this by redefining the initialize method
again in Mod2::B, such that it looks exactly the same as Mod1::B, but I'm
hoping to find a trick to avoid having to do that.

Any thoughts?

Caleb


6 Answers

Eero Saynatkari

12/14/2005 9:23:00 PM

0

Caleb Tennis wrote:
> Here's a small snippet of code I'm trying to hack on:
>
> <snip due to ruby-forum.com quote limit />
>
> What I'm trying to accomplish is having B reference A but in the same
> module
> its currently in. I can accomplish this by redefining the initialize
> method
> again in Mod2::B, such that it looks exactly the same as Mod1::B, but
> I'm
> hoping to find a trick to avoid having to do that.
>
> Any thoughts?

You could use #const_get, possibly, since a method call is dynamic.

> Caleb


E

--
Posted via http://www.ruby-....


Its Me

12/15/2005 10:54:00 PM

0

module M1
class A; def foo; "foo"; end; end
end

module M2
A = M1::A
class A; def bar; "bar"; end; end
end

a = M2::A

a.foo #=> "foo"
a.bar #=> "bar"

Is that what you meant?

However, note that:

M2::A == M1::A

"Caleb Tennis" <caleb@aei-tech.com> wrote in message
news:200512141601.46013.caleb@aei-tech.com...
> Here's a small snippet of code I'm trying to hack on:
>
> module Mod1
> class A
> def meth
> puts "in Mod 1"
> end
> end
>
> class B
> def initialize
> A.new.meth
> end
> end
> end
>
> module Mod2
> class A < Mod1::A
> def meth
> put "in Mod 2"
> end
> end
>
> class B < Mod1::B
> end
> end
>
> p Mod1::B.new
> p Mod2::B.new
>
>
>
> caleb@tcdevel ~ $ ruby testit.rb
> in Mod 1
> #<Mod1::B:0xb7c888dc>
> in Mod 1
> #<Mod2::B:0xb7c88508>
>
> What I'm trying to accomplish is having B reference A but in the same
> module
> its currently in. I can accomplish this by redefining the initialize
> method
> again in Mod2::B, such that it looks exactly the same as Mod1::B, but I'm
> hoping to find a trick to avoid having to do that.
>
> Any thoughts?
>
> Caleb
>
>


Lamont Cranston

8/7/2008 7:32:00 PM

0

The Weasel wrote:
> On Aug 7, 2:10 pm, TammyFranks <jismqu...@yahoo.com>
> wrote:
>> McDrain should pick either Cringin' Colin Powell, or
>> Mahvalous Mitt
>> Romney for his VP.
>>
>> The Dems would have a ball with either of these two
>> dissembling,
>> lying, YES-MEN!
>
> If McCain picks Romney, Obama, the empty suit, would lose
> the
> Electoral College by 50 votes.

It doesn't matter who McCain, the empty baseball cap, picks.
Obama will win the EC by 100 votes.

Gandalf Grey

8/7/2008 7:36:00 PM

0


"Lamont Cranston" <Lamont.Cranston@intheshadows.com> wrote in message
news:g7figq$ka3$1@news.datemas.de...
> The Weasel wrote:
>> On Aug 7, 2:10 pm, TammyFranks <jismqu...@yahoo.com> wrote:
>>> McDrain should pick either Cringin' Colin Powell, or Mahvalous Mitt
>>> Romney for his VP.
>>>
>>> The Dems would have a ball with either of these two dissembling,
>>> lying, YES-MEN!
>>
>> If McCain picks Romney, Obama, the empty suit, would lose the
>> Electoral College by 50 votes.
>
> It doesn't matter who McCain, the empty baseball cap, picks. Obama will
> win the EC by 100 votes.

The repugs are whistling as they walk by the graveyard. In their dark
little hearts they know they've lost the House the Senate and the
presidency. But there will be a lot of bluster before the day when they're
dragged out of Washington kicking and screaming.

>


The Weasel

8/10/2008 1:56:00 AM

0

On Aug 7, 2:32 pm, "Lamont Cranston"
<Lamont.Crans...@intheshadows.com> wrote:
> The Weasel wrote:
> > On Aug 7, 2:10 pm, TammyFranks <jismqu...@yahoo.com>
> > wrote:
> >> McDrain should pick either Cringin' Colin Powell, or
> >> Mahvalous Mitt
> >> Romney for his VP.
>
> >> The Dems would have a ball with either of these two
> >> dissembling,
> >> lying, YES-MEN!
>
> > If McCain picks Romney, Obama, the empty suit, would lose
> > the
> > Electoral College by 50 votes.
>
> It doesn't matter who McCain, the empty baseball cap, picks.
> Obama will win the EC by 100 votes.


Not at this rate.

325 Obama, 199 McCain, 14 tie

http://www.electoral-vote.com/evp2008/Pres/Maps/...

289 Obama, 236 McCain, 13 tie

http://www.electoral-vote.com/evp2008/Pres/Maps/...

As soon as Indiana is polled again, Obama will drop again.

Clay

8/10/2008 2:47:00 AM

0

On Aug 7, 3:36?pm, "Gandalf Grey" wrote:
...

> "Lamont Cranston" <Lamont.Crans...@intheshadows.com> wrote in message
>
> news:g7figq$ka3$1@news.datemas.de...
>
> > The Weasel wrote:
> >> On Aug 7, 2:10 pm, TammyFranks <jismqu...@yahoo.com> wrote:
> >>> McDrain should pick either Cringin' Colin Powell, or Mahvalous Mitt
> >>> Romney for his VP.
>
> >>> The Dems would have a ball with either of these two dissembling,
> >>> lying, YES-MEN!
>
> >> If McCain picks Romney, Obama, the empty suit, would lose the
> >> Electoral College by 50 votes.
>
> > It doesn't matter who McCain, the empty baseball cap, picks. Obama will
> > win the EC by 100 votes.
>
> The repugs are whistling as they walk by the graveyard. ?

At this point, I think Obama will be our next POTUS. But it won't be
the blowout many think.

He prolly won't win one state from "the old South".

> In their dark
> little hearts they know they've lost the House the Senate and the
> presidency. ?

Perhaps.

> But there will be a lot of bluster before the day when they're
> dragged out of Washington kicking and screaming.

Again... this is simply wrong.

Come January 2009, there will be Republicans in the House... there
will be Republicans in the Senate.

There will continue to be places like "National Review", "The Weekly
Standard" and the Heritage Foundation.

No need to worry... I am not.

-C-