Without writing my own alias, is there an easy way to get the class of
the current object without calling self.class? I'm trying to call class
methods from within an instance method, and self.class.method_name is
just a little verbose for my taste. I could do type.method_name, but
that's deprecated and not very clear. It would be nice if just class
by itself were understood in context as the method instead of the keyword,
but since it's not, I'm sort of stuck. Suggestions?
class Object
def klass
self.class
end
end
often i simply put this in specific classes. i also put this one in alot
class Object
def singleton_class
class << self; self; end
end
end
it defintely best if you can keep this in your own code - but sometimes
putting global like this makes sense.
regards.
-a
···
On Mon, 19 Dec 2005, Mark J.Reed wrote:
Without writing my own alias, is there an easy way to get the class of
the current object without calling self.class? I'm trying to call class
methods from within an instance method, and self.class.method_name is
just a little verbose for my taste. I could do type.method_name, but
that's deprecated and not very clear. It would be nice if just class
by itself were understood in context as the method instead of the keyword,
but since it's not, I'm sort of stuck. Suggestions?
--
ara [dot] t [dot] howard [at] noaa [dot] gov
all happiness comes from the desire for others to be happy. all misery
comes from the desire for oneself to be happy.
-- bodhicaryavatara
===============================================================================
Mark J. Reed wrote:
Without writing my own alias, is there an easy way to get the class of
the current object without calling self.class? I'm trying to call class
methods from within an instance method, and self.class.method_name is
just a little verbose for my taste. I could do type.method_name, but
that's deprecated and not very clear. It would be nice if just class
by itself were understood in context as the method instead of the keyword,
but since it's not, I'm sort of stuck. Suggestions?
I think it's a good idea to allow `class' to be called from within methods if there's a dot after it
class.some_method # legal
class # illegal, or rather, creates a new class
I also think that `when' should only be reserved when inside a case statement. There's no need to reserve words in places where they're not going to be used for that purpose anyway.
Cheers,
Daniel
never really thought about this, but this might be a useful method:
def new
self.class.new
end
what are your thoughts?
greetings, Dirk.
···
2005/12/19, Mark J. Reed <mreed@thereeds.org>:
Without writing my own alias, is there an easy way to get the class of
the current object without calling self.class? I'm trying to call class
methods from within an instance method, and self.class.method_name is
just a little verbose for my taste. I could do type.method_name, but
that's deprecated and not very clear. It would be nice if just class
by itself were understood in context as the method instead of the keyword,
but since it's not, I'm sort of stuck. Suggestions?
Daniel Schierbeck ha scritto:
Mark J. Reed wrote:
Without writing my own alias, is there an easy way to get the class of
the current object without calling self.class? I'm trying to call class
methods from within an instance method, and self.class.method_name is
just a little verbose for my taste. I could do type.method_name, but
that's deprecated and not very clear. It would be nice if just class
by itself were understood in context as the method instead of the keyword,
but since it's not, I'm sort of stuck. Suggestions?I think it's a good idea to allow `class' to be called from within methods if there's a dot after it
class.some_method # legal
class # illegal, or rather, creates a new class
+1, but I wonder if this may be a limitation of the parser
gabriele renzi wrote:
Daniel Schierbeck ha scritto:
Mark J. Reed wrote:
Without writing my own alias, is there an easy way to get the class of
the current object without calling self.class? I'm trying to call class
methods from within an instance method, and self.class.method_name is
just a little verbose for my taste. I could do type.method_name, but
that's deprecated and not very clear. It would be nice if just class
by itself were understood in context as the method instead of the keyword,
but since it's not, I'm sort of stuck. Suggestions?I think it's a good idea to allow `class' to be called from within methods if there's a dot after it
class.some_method # legal
class # illegal, or rather, creates a new class+1, but I wonder if this may be a limitation of the parser
Probably. I'm getting a bit fed up with the current parser, it seems to kill off a lot of good ideas. What's the status on that new ANTLR grammar?
Cheers,
Daniel
Quoting gabriele renzi <surrender_it@-remove-yahoo.it>:
> I think it's a good idea to allow `class' to be called from
within
> methods if there's a dot after it
>
> class.some_method # legal
> class # illegal, or rather, creates a new class+1, but I wonder if this may be a limitation of the parser
You could do it with some work, I think, but it'd make the grammar
even uglier. self.class only works right now because the 'meth'
in:
obj.meth
is treated totally differently than 'meth' in:
meth
Making class.meth another way to write self.class.meth would be a
bit like asking for e.g.:
[1]
on a line by itself to be an alias for
self[1]
-mental
Quoting Daniel Schierbeck daniel.schierbeck-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org:
class.some_method # legal
class # illegal, or rather, creates a new class+1, but I wonder if this may be a limitation of the parser
Probably. I’m getting a bit fed up with the current parser, it
seems to kill off a lot of good ideas. What’s the status on that
new ANTLR grammar?
Ter’s still learning Ruby and I’m still learning ANTLR.
-mental
Quoting mental@rydia.net:
Quoting gabriele renzi <surrender_it@-remove-yahoo.it>:
> > I think it's a good idea to allow `class' to be called from
> within
> > methods if there's a dot after it
> >
> > class.some_method # legal
> > class # illegal, or rather, creates a new
class
>
> +1, but I wonder if this may be a limitation of the parserYou could do it with some work, I think, but it'd make the
grammar even uglier.
Well, I take that back, sort of. You've got to do lookahead for <
versus << after class anyway.
I think I will have a better sense of what's going to look
reasonable once I've gotten further on the subset grammar (I guess
I'll devote some time to that tonight).
-mental
Yeah, it may be awhile before I have enough time to learn ruby
sufficiently to parse it. It’s a very complicated language when you
peer into the edge cases. Makes python look simple.
Ter
···
On Dec 19, 2005, at 12:21 PM, mental-uFjFfPRxV21eoWH0uzbU5w@public.gmane.org wrote:
Quoting Daniel Schierbeck daniel.schierbeck-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org:
class.some_method # legal
class # illegal, or rather, creates a new class+1, but I wonder if this may be a limitation of the parser
Probably. I’m getting a bit fed up with the current parser, it
seems to kill off a lot of good ideas. What’s the status on that
new ANTLR grammar?Ter’s still learning Ruby and I’m still learning ANTLR.
Quoting Terence Parr parrt-XeM6X/PiNgr2fBVCVOL8/A@public.gmane.org:
Yeah, it may be awhile before I have enough time to learn ruby
sufficiently to parse it. It’s a very complicated language when
you peer into the edge cases. Makes python look simple.
I think what I’m going to do at this point is go ahead and start on
that v2 grammar for a Ruby subset, just so we keep our forward
momentum. We’ll migrate to v3 when that’s a little more baked.
As far as Ruby goes, I’m definitely going to need your help for the
weird stuff (e.g. heredocs), but most of the edge cases are just
edge cases and I think I can deal with those.
-mental
Quoting Terence Parr parrt-XeM6X/PiNgr2fBVCVOL8/A@public.gmane.org:
Yeah, it may be awhile before I have enough time to learn ruby
sufficiently to parse it. It’s a very complicated language when
you peer into the edge cases. Makes python look simple.I think what I’m going to do at this point is go ahead and start on
that v2 grammar for a Ruby subset, just so we keep our forward
momentum. We’ll migrate to v3 when that’s a little more baked.
Kewl.
As far as Ruby goes, I’m definitely going to need your help for the
weird stuff (e.g. heredocs), but most of the edge cases are just
edge cases and I think I can deal with those.
No worries. I think that we should consider a stream object that
processes all random delimiters into a standard one and then the
lexer has it easy.
Ter
···
On Dec 20, 2005, at 2:28 PM, mental-uFjFfPRxV21eoWH0uzbU5w@public.gmane.org wrote: