[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: How to extend class with the particular method

Robert Dober

11/1/2007 3:47:00 PM

On 11/1/07, Nikolay Pavlov <qpadla@gmail.com> wrote:
> Hello.
> I have a class and a module. I want to extend a class with a particular
> method that is defined in a module. I have come up to the following
> example code, but i am not sure how to implement a
> Operational::Behavior#proc method. Could some one please help me in this?
> Or may be prompt a better implementation?
>
> ====================================================
> class SomeClass
> include Operational
>
> operational_as :bob
> end
>
>
> module Operational
> def self.included(base)
> base.extend ClassMethods
> end
>
> module ClassMethods
> def operational_as(method)
> klass = class << self; self; end
> klass.instance_eval do
> define_method(method.to_sym, Behavior.proc(method.to_sym))
> end
> end
> end
>
> module Behavior
>
> def self.proc(method)
> end
>
> private
>
> def bob
> ...
> end
>
> def sam
> ...
> end
> end
> end
> =========================================
>
> --
> ======================================================================
> - Best regards, Nikolay Pavlov. <<<-----------------------------------
> ======================================================================
>
>
>
Hmm I am not 100% sure what you want exactly
if I understand correctly you want to include a single method of a
module into whatever.
I have implemented this in traits but the overhead is big, you can
however see in the code
how this is done.
Maybe it is worthy to look into the "use" package, written by Daniel.
It does *exactly* and *only* that.This has been discussed in the
original announcement of the traits
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
If you want to check out traits here is the link anyway:
http://rubyforge.org/frs/?group_id=4642&releas...

Ok maybe an example would be in order, just to be sure that it does
what you want
before digging into the code.

require 'pure-traits'

T = trait {
def a; 42 end
def b; 222 end
}

class C
class << self
use T & [:a]
end
end

puts C.a
puts C.b

HTH
Robert
--
what do I think about Ruby?
http://ruby-smalltalk.blo...

8 Answers

NEMO

2/26/2012 7:09:00 AM

0

The only German I need to know is what my grandfather learned in WW1 &
what my father learned in WW2:

"Hand hoch, you square - head Jerry Kraut bastards!"

It worked for them!

Ayup!

Heinrich

2/26/2012 7:17:00 AM

0



"NEMO" schreef in bericht
news:ff49df10-1028-44f8-a671-79e5ae60ce95@w1g2000vbg.googlegroups.com...

The only German I need to know is what my grandfather learned in WW1 &
what my father learned in WW2:

"Hand hoch, you square - head Jerry Kraut bastards!"

It worked for them!

Ayup!


that is no german. this should read: Haende hoch. if you do not learn the
german language you will be on welfare very soon and there will be no escape
possible from the ovens

NEMO

2/26/2012 7:31:00 AM

0

You, you Dutch coward!

Just try, just try & you'll end up like the Kraut bastards my
grandfather & father ran into - face down in a ditch with a bullet
hole in their heads, while they screamed, "Mutter - mutter!" & they
put another bullet in their head to end the Kraut bastards crying like
a little girl!

Bang - bang, one dead Hun!

Ayup!

der Julius

2/26/2012 7:42:00 AM

0



"NEMO" schreef in bericht
news:4d9b77ab-c138-4905-9759-c88284294dc6@hs8g2000vbb.googlegroups.com...

You, you Dutch coward!

Just try, just try & you'll end up like the Kraut bastards my
grandfather & father ran into - face down in a ditch with a bullet
hole in their heads, while they screamed, "Mutter - mutter!" & they
put another bullet in their head to end the Kraut bastards crying like
a little girl!

Bang - bang, one dead Hun!

Ayup!

o yes i love those heroic stories of those who partiipated in the war. let
me tell you this that 98 percent of those stories are ccomplete bullshit
asand not true at all.

NEMO

2/26/2012 7:59:00 AM

0

How would you know, coward, your family were Nazi collaborators!

Did the Free Dutch shave your mother's head & beat your father up
until he was a dopey as you are!

Hah!

NEMO

2/26/2012 8:33:00 AM

0

" the canadian troops did nothing to prevent this disgusting course of
things"

We encouraged the Free Duch & then the Canucks fooked every Dutch girl
in sight!

& I fooked 3 Dutch girls 25 years later!

The Peeler

2/26/2012 10:21:00 AM

0

On Sun, 26 Feb 2012 07:57:46 +0100, der Julius, better known as Dumb Heini,
the Dutch resident Nazi troll of sci and scj, wrote:

> Just ask der Julius, Mouse Droppings & Hans - Peter Skaliks!
>
> the german language is the language of the future so be smart and try to
> learn to speak and understand it

Rest assured that the vast majority of Germans (and the Dutch) would SPIT on
you, if they knew about your sick online "activities", you abnormal pathetic
loser from Holland!!!


--
Dumb Dutch Nazi Heini's motto: "to suck rectum or not to suck rectum that is
the question"
MID: <4db7abbb$0$24816$2e0edba0@news.tweakdsl.nl>

The Peeler

2/26/2012 10:21:00 AM

0

On Sun, 26 Feb 2012 09:21:48 +0100, der Julius, better known as Dumb Heini,
the Dutch resident Nazi troll of sci and scj, wrote:

> free dutch? free cowards you mean.those idiots kept quite for five years and
> after the germans had gone they dare to come up in the open and to molest
> women and children who could not defende themselves. needless to say that
> the canadian troops did nothing to prevent this disgusting course of things

So your collaborationist family experienced some tough times after the Nazis
were gone. Good to know, you mentally handicapped Dutch Nazi swine! LOL


--
The Dutch Nazitard: why do you americans always have to call me hei9nnie
while my posatings clearly indicaate my name is heinrich?
MID: <4dad5b41$0$20532$2e0edba0@news.tweakdsl.nl>