[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Musings on module/class definition domains

T. Onoma

10/6/2004 3:49:00 PM

I find Ruby's various means of accessing class "domain" a bit clunky. Between
class << self, extend self, module_function, def AClass.foo, def self.foo,
and so forth. So I muse on what might be more uniform and easily
comprehensible.

class Example
metaclass
def foo
puts "Class Method"
end
instance
def foo
puts "Instance Method"
end
extended
def bar
puts "Class Method && Instance Method"
end
end

And with variations:

class Example
instance private
def foo
puts "Instance Method"
end
extended instance private # just like module_function
def bar
puts "Class Method && Instance Method"
end
end

T.


5 Answers

Martin DeMello

10/7/2004 5:50:00 AM

0

"trans. (T. Onoma)" <transami@runbox.com> wrote:
> extended
> def bar
> puts "Class Method && Instance Method"
> end

What would the value of 'self' be?

martin

T. Onoma

10/7/2004 10:55:00 AM

0

On Thursday 07 October 2004 01:54 am, Martin DeMello wrote:
| "trans. (T. Onoma)" <transami@runbox.com> wrote:
| > extended
| > def bar
| > puts "Class Method && Instance Method"
| > end
|
| What would the value of 'self' be?

Sorry, I should have clarified what his means. The above is basically the same
as currently doing:

extend self
def bar
puts "Class Method && Instance Method"
end

Which is why I called it extended. It is almost, but not quite, the same thing
as doing:

metaclass
def bar
puts "Class Method && Instance Method"
end
instance
def bar
puts "Class Method && Instance Method"
end

Does that answer the question, or am I misunderstanding?

T.


Martin DeMello

10/8/2004 6:15:00 AM

0

"trans. (T. Onoma)" <transami@runbox.com> wrote:
as doing:
>
> metaclass
> def bar
> puts "Class Method && Instance Method"
> end
> instance
> def bar
> puts "Class Method && Instance Method"
> end
>
> Does that answer the question, or am I misunderstanding?

I was just wondering about the utility of a method that got attached
both to the class and the instance, since the value of 'self' would be
very different in each case. Can you give me an example?

martin

Mauricio Fernández

10/8/2004 8:48:00 AM

0

On Fri, Oct 08, 2004 at 03:14:46PM +0900, Martin DeMello wrote:
> "trans. (T. Onoma)" <transami@runbox.com> wrote:
> as doing:
> >
> > metaclass
> > def bar
> > puts "Class Method && Instance Method"
> > end
> > instance
> > def bar
> > puts "Class Method && Instance Method"
> > end
> >
> > Does that answer the question, or am I misunderstanding?
>
> I was just wondering about the utility of a method that got attached
> both to the class and the instance, since the value of 'self' would be
> very different in each case. Can you give me an example?

Math::sin 1
include Math
sin 1

--
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com



Notroll2010

4/10/2010 1:39:00 AM

0


"ChasNemo" <chasnemo@gmail.com> wrote in message
news:b9dbc726-deb7-459f-a1a0-b59870064ab3@i37g2000yqn.googlegroups.com...
On Apr 9, 9:01?pm, "Hagar" <hagen@sahm,name> wrote:
> "John Griffin" <thathillbi...@yahooie.com> wrote in message
>
> news:Xns9D546706857E9thathillbillyyahooco@130.133.4.11...
>
>
>
> > "Cowhand" ChasNemo <chasn...@gmail.com> wrote:
>
> >> Since the Supremist White Wing Court has determined that
> >> corporations are people, [yap yap yap]....
>
> > Who would have expected such a supremely idiotic, colossally lame
> > misconstruction from supremely dysfunctional cow-boinker Nemo?
> > Hint: Since Nemo's spirochetes have taken total control of the
> > slop between his ears...who wouldn't have?
>
> > Seriously, dim one, that was even dumber than pompous pretender
> > Obama's ignorant remark in his "state of the union" teleprompter
> > reading.
>
> > --
> > "You may have to give up a piece of your pie so that someone
> > else can have more." ?--Obama, explicitly endorsing Karl Marx's
> > "Ideal state of communism: ?From each according to his ability,
> > to each according to his need."
>
> Could slobNemaToad be ... gasp ... Obama's Lewinski ???- Hide quoted
> text -
>
> - Show quoted text -

Hagar is Griffuck's Senator Larry Craig.

*****************************************************************
Clearly there are few branches in either of their family trees. A more
inbred pair of crackers is seldom seen.