[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

define_method

Malcolm Lockyer

11/7/2007 4:38:00 AM

Hi Guys,

I am trying to use define_method like:

class TestClass
def initialize
define_method("hello") { || puts "Hello" }
end
end

x = TestClass.new
x.hello

I am always getting:
NoMethodError: undefined method `define_method'

Do I need to require something? Am I doing something wrong, or am I
completely missing the boat!?


Any help appreciated!

Thanks,
Malcolm.

10 Answers

Trans

11/7/2007 7:08:00 AM

0



On Nov 6, 11:37 pm, "Malcolm Lockyer" <maxpeng...@gmail.com> wrote:
> Hi Guys,
>
> I am trying to use define_method like:

def selfclass
(class << self; self; end)
end

class TestClass
def initialize
selfclass.send(:define_method, "hello") { || puts "Hello" }
end
end

x = TestClass.new
x.hello


Jacob Basham

11/7/2007 7:16:00 AM

0

You are getting this error since define_method is defined in Module
not Object. Your object needs to call define_method against it's Class
definition, not self.

Here's an example how to use it.
http://www.ruby-doc.org/core/classes/Module.ht...

Best,
Jake

On Nov 6, 2007, at 10:37 PM, Malcolm Lockyer wrote:

> Hi Guys,
>
> I am trying to use define_method like:
>
> class TestClass
> def initialize
> define_method("hello") { || puts "Hello" }
> end
> end
>
> x = TestClass.new
> x.hello
>
> I am always getting:
> NoMethodError: undefined method `define_method'
>
> Do I need to require something? Am I doing something wrong, or am I
> completely missing the boat!?
>
>
> Any help appreciated!
>
> Thanks,
> Malcolm.
>


Robert Klemme

11/7/2007 12:41:00 PM

0

2007/11/7, Malcolm Lockyer <maxpenguin@gmail.com>:
> Hi Guys,
>
> I am trying to use define_method like:
>
> class TestClass
> def initialize
> define_method("hello") { || puts "Hello" }
> end
> end
>
> x = TestClass.new
> x.hello
>
> I am always getting:
> NoMethodError: undefined method `define_method'
>
> Do I need to require something? Am I doing something wrong, or am I
> completely missing the boat!?

Is this really your use case? Since you know which method you define,
you can do it with a normal def anyway. So I suspect that you are
doing something else. What exactly is it?

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end

Malcolm Lockyer

11/7/2007 9:19:00 PM

0

Hey, thanks for the replies guys, I am pretty noob with ruby so thanks
for your help.

Yes Robert, that wasn't my use case - that was just the most
simplified code that shows the problem I was having. I didn't want to
bore you all with loads of irrelevant code. If you are interested I
was trying to build a dynamic enumeration style class (vaguely similar
to java or c#'s way of doing it), where I could have the pseudo
constant (i.e. TestClass.Blue, TestClass.Red etc.) setup by calling
the constructor something like TestClass.new(:Blue => 1, :Red => 2
etc.) and also be able to iterate through the keys and stuff.


Anyway, thanks again for your help guys.
Malcolm

On 11/8/07, Malcolm Lockyer <malcolm@endev.co.nz> wrote:
> Hey, thanks for the replies guys, I am pretty noob with ruby so thanks
> for your help.
>
> Yes Robert, that wasn't my use case - that was just the most
> simplified code that shows the problem I was having. I didn't want to
> bore you all with loads of irrelevant code. If you are interested I
> was trying to build a dynamic enumeration style class (vaguely similar
> to java or c#'s way of doing it), where I could have the pseudo
> constant (i.e. TestClass.Blue, TestClass.Red etc.) setup by calling
> the constructor something like TestClass.new(:Blue => 1, :Red => 2
> etc.) and also be able to iterate through the keys and stuff.
>
>
> Anyway, thanks again for your help guys.
> Malcolm
>
> On 11/8/07, Robert Klemme <shortcutter@googlemail.com> wrote:
> > 2007/11/7, Malcolm Lockyer <maxpenguin@gmail.com>:
> > > Hi Guys,
> > >
> > > I am trying to use define_method like:
> > >
> > > class TestClass
> > > def initialize
> > > define_method("hello") { || puts "Hello" }
> > > end
> > > end
> > >
> > > x = TestClass.new
> > > x.hello
> > >
> > > I am always getting:
> > > NoMethodError: undefined method `define_method'
> > >
> > > Do I need to require something? Am I doing something wrong, or am I
> > > completely missing the boat!?
> >
> > Is this really your use case? Since you know which method you define,
> > you can do it with a normal def anyway. So I suspect that you are
> > doing something else. What exactly is it?
> >
> > Kind regards
> >
> > robert
> >
> > --
> > use.inject do |as, often| as.you_can - without end
> >
> >
>

Robert Klemme

11/8/2007 7:01:00 AM

0


Please do not top post.

On 07.11.2007 22:19, Malcolm Lockyer wrote:
> Yes Robert, that wasn't my use case - that was just the most
> simplified code that shows the problem I was having. I didn't want to
> bore you all with loads of irrelevant code. If you are interested I
> was trying to build a dynamic enumeration style class (vaguely similar
> to java or c#'s way of doing it), where I could have the pseudo
> constant (i.e. TestClass.Blue, TestClass.Red etc.) setup by calling
> the constructor something like TestClass.new(:Blue => 1, :Red => 2
> etc.) and also be able to iterate through the keys and stuff.

In case you are not doing it for the fun of it and / or are looking for
more inspirations this is a good place to look:

http://raa.ruby-lang.org/search.rhtml?s...

Kind regards

robert

Yoorghis

6/20/2011 3:43:00 AM

0

On Sun, 19 Jun 2011 14:35:39 -0700 (PDT), Richard Steel
<rsteel2525@aol.com> wrote:

>On Jun 19, 2:13?pm, Yoorg...@Jurgis.net wrote:
>> On Sun, 19 Jun 2011 10:26:17 -0700 (PDT), Richard Steel
>>
>> <rsteel2...@aol.com> wrote:
>> >On Jun 18, 5:42?pm, "6082 Dead, 1225 since 1/20/09" <d...@gone.com>
>> >> > His posts are more of bluster than anything else - do you ever wonder
>> >> > what he is compensating for?
>>
>> >> I have a bad tendency to pity right wingers and want to help them,
>>
>> >No, you are a bitter old fool who has become increasing hysterical as
>> >it become more and more impossible to ignore the truth - that pretty
>> >much everything you believe in is a lie, and that you're on the wrong
>> >side of history.
>>
>> Guffaw
>>
>> You can't name a single thing in the History of America that
>> conservatives ever did to make this a better nation.
>
>Oh, you're pulling out THAT one again?

It's historical fact

>Let's cut to the chase. You define EVERYTHING good as liberal, and
>everything bad as conservative.

Do something good and you get credit.

>According to you, Teddy Roosevelt, Richard Nixon, Abe Lincoln, Warren
>G. Harding, and Calvin Coolidge were liberals, while FDR, Woodrow
>Wilson, Harry Truman, LBJ and JFK were conservatives.

TR Roosevelt was considered Progressive, As was Lincoln.

As usual you make a stupid claim, then demand that your conclusion be
fact/truth. It's fallacy argument

Policies and programs and use of government to benefit the society it
serves is why Lincoln, T.R. FDR, Kennedy, Clinton were great and good
for America

Nixon, reagan, Bush-the-idiot and conservative policy thu generations
fought AGAINST every major innovation and good thing that made America
great

Once again, tell us what Conservatism did to make America better.

>There will come a day when you will claim that Ronald Reagan and
>George W. Bush were liberals

Only thing Dumbya and raygun were, was liars.




>=============================================================

On Fri, 18 Sep 2009 16:32:34 -0700 (PDT),
Kurtis T. Nicklas

<nickl...@bellsouth.net> wrote in message


>I don't pay much attention to him these days, but I'd wager he's not
>happy.

You sure as shit paid attention when you got caught
making all those late-night hang-up phone calls, didn't
ya, Nickkkkers?

CLICK ! ! !

Richard Steel

6/20/2011 5:34:00 AM

0

On Jun 19, 8:43 pm, Yoorg...@Jurgis.net wrote:
> On Sun, 19 Jun 2011 14:35:39 -0700 (PDT), Richard Steel
>
>
>
>
>
>
>
>
>
> <rsteel2...@aol.com> wrote:
> >On Jun 19, 2:13 pm, Yoorg...@Jurgis.net wrote:
> >> On Sun, 19 Jun 2011 10:26:17 -0700 (PDT), Richard Steel
>
> >> <rsteel2...@aol.com> wrote:
> >> >On Jun 18, 5:42 pm, "6082 Dead, 1225 since 1/20/09" <d...@gone.com>
> >> >> > His posts are more of bluster than anything else - do you ever wonder
> >> >> > what he is compensating for?
>
> >> >> I have a bad tendency to pity right wingers and want to help them,
>
> >> >No, you are a bitter old fool who has become increasing hysterical as
> >> >it become more and more impossible to ignore the truth - that pretty
> >> >much everything you believe in is a lie, and that you're on the wrong
> >> >side of history.
>
> >> Guffaw
>
> >> You can't name a single thing in the History of America that
> >> conservatives ever did to make this a better nation.

> >Oh, you're pulling out THAT one again?

> It's historical fact

When you claim that your side is the only one which is virtuous - that
is literal madness, and I'm not indulging it anymore.

Yoorghis

6/20/2011 1:18:00 PM

0

On Sun, 19 Jun 2011 22:34:16 -0700 (PDT), Richard Steel
<rsteel2525@aol.com> wrote:

>On Jun 19, 8:43?pm, Yoorg...@Jurgis.net wrote:


>> >> You can't name a single thing in the History of America that
>> >> conservatives ever did to make this a better nation.
>
>> >Oh, you're pulling out THAT one again?
>
>> It's historical fact
>
>When you claim that your side is the only one which is virtuous - that
>is literal madness, and I'm not indulging it anymore.

You can't afford to Steel

You can't answer the question, history is against you.

One of the few things conservatives were good for---was to act as a
"brake" on the exuberance of progressives to affect policy that helped
this nation.

Yet your ideology fought to KEEP every racist, homphobic, greedy
policy from racism to using failed economic theory to amass more and
more wealth to fewer and fewer people.




>=============================================================

On Fri, 18 Sep 2009 16:32:34 -0700 (PDT),
Kurtis T. Nicklas

<nickl...@bellsouth.net> wrote in message


>I don't pay much attention to him these days, but I'd wager he's not
>happy.

You sure as shit paid attention when you got caught
making all those late-night hang-up phone calls, didn't
ya, Nickkkkers?

CLICK ! ! !

Richard Steel

6/20/2011 3:16:00 PM

0

On Jun 20, 6:17 am, Yoorg...@Jurgis.net wrote:
> On Sun, 19 Jun 2011 22:34:16 -0700 (PDT), Richard Steel
>
> <rsteel2...@aol.com> wrote:
> >On Jun 19, 8:43 pm, Yoorg...@Jurgis.net wrote:
> >> >> You can't name a single thing in the History of America that
> >> >> conservatives ever did to make this a better nation.
>
> >> >Oh, you're pulling out THAT one again?
>
> >> It's historical fact
>
> >When you claim that your side is the only one which is virtuous - that
> >is literal madness, and I'm not indulging it anymore.
>
> You can't ....

I'm not indulging your literal madness anymore.

(rest deleted unread)

Richard Steel

6/20/2011 5:06:00 PM

0

On Jun 20, 9:35 am, "6082 Dead, 1225 since 1/20/09" <d...@gone.com>
wrote:
> On Mon, 20 Jun 2011 08:15:31 -0700, Richard Steel wrote:
> > On Jun 20, 6:17 am, Yoorg...@Jurgis.net wrote:
> >> On Sun, 19 Jun 2011 22:34:16 -0700 (PDT), Richard Steel
>
> >> <rsteel2...@aol.com> wrote:
> >> >On Jun 19, 8:43 pm, Yoorg...@Jurgis.net wrote:
> >> >> >> You can't name a single thing in the History of America that
> >> >> >> conservatives ever did to make this a better nation.
>
> >> >> >Oh, you're pulling out THAT one again?
>
> >> >> It's historical fact
>
> >> >When you claim that your side is the only one which is virtuous - that
> >> >is literal madness, and I'm not indulging it anymore.
>
> >> You can't ....
>
> > I'm not indulging your literal madness anymore.
>
> > (rest deleted unread)

> So tell us something conservatives have ever done to benefit the American
> people.

I'm not indulging your madness anymore. When you insist that your
side has done everything good ever done, and the other had never done
anything virtuous - that's literal insanity.

While having this "discussion" with the loony Yoorg - I was informed
that FDR was a conservative when he rounded up every Japanese
American, that Nixon was a liberal when he started affirmative action
and the EPA. That Harry Truman was a conservative when he joined the
KKK.

The reason for this game is to promote the idea that virtue is won,
not by how one lives, but by which polling booth lever is pulled.

My, my, isn't that wonderful? A trip around the corner, sign a book,
vote straight Democrat, then nothing you do for the rest of the year
is bad. Sort of like the Christian who attends Church every Sunday,
then sins Monday through Saturday. The difference being that the
Christian actually attends church every week, and can be shamed into
good behavior.

You want an excuse to treat people who disagree with you like shit,
You justify childish, arrogant, actually evil behavior by pretending
that conservatives have never done a single good thing in their entire
history.

You've got vicious behavior down to a science - anyone who disagrees
with you is a "racist", a "liar", a "hate" or some other vague term
designed to make the person bluster.

We all know your games, are we're though treating you folks like
adults.

Now, you'll excuse me while I snicker at your bluster.