Forum: Ruby __PRETTY__FUNCTION__ for Ruby?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D812408537ac3a0fa2fec96eb8811559?d=identicon&s=25 John Carter (johncarter)
on 2008-12-14 22:31
(Received via mailing list)
We have __FILE__ and __LINE__....

So it would be nice to have __PRETTY_FUNCTION__?

Is there one or do I have to roll my own out of "caller(1)[0]"?



John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter@tait.co.nz
New Zealand
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2008-12-15 00:08
(Received via mailing list)
Hi,

In message "Re: __PRETTY__FUNCTION__ for Ruby?"
    on Mon, 15 Dec 2008 06:23:08 +0900, John Carter
<john.carter@tait.co.nz> writes:

|We have __FILE__ and __LINE__....
|
|So it would be nice to have __PRETTY_FUNCTION__?
|
|Is there one or do I have to roll my own out of "caller(1)[0]"?

You mean __method__ in 1.9?

              matz.
D812408537ac3a0fa2fec96eb8811559?d=identicon&s=25 John Carter (johncarter)
on 2008-12-15 01:50
(Received via mailing list)
On Mon, 15 Dec 2008, Yukihiro Matsumoto wrote:

> |We have __FILE__ and __LINE__....
> |
> |So it would be nice to have __PRETTY_FUNCTION__?
> |
> |Is there one or do I have to roll my own out of "caller(1)[0]"?
>
> You mean __method__ in 1.9?

Ah! Sorry! I was looking under the wrong name....

Now, thank you, I'm looking in the right place so I see.....

ruby --version
ruby 1.8.7 (2008-06-20 patchlevel 22) [i686-linux]
$ ruby -e 'def foo;p __method__;end;foo'
:foo

Are you're saying that this behaviour change in 1.9?


John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter@tait.co.nz
New Zealand
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2008-12-15 02:43
(Received via mailing list)
Hi,

In message "Re: __PRETTY__FUNCTION__ for Ruby?"
    on Mon, 15 Dec 2008 09:42:01 +0900, John Carter
<john.carter@tait.co.nz> writes:

|ruby --version
|ruby 1.8.7 (2008-06-20 patchlevel 22) [i686-linux]
|$ ruby -e 'def foo;p __method__;end;foo'
|:foo
|
|Are you're saying that this behaviour change in 1.9?

No, 1.8.7 just added a lot of 1.9 features recently.

              matz.
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2008-12-15 05:15
(Received via mailing list)
On Sun, Dec 14, 2008 at 7:42 PM, John Carter <john.carter@tait.co.nz>
wrote:
> Ah! Sorry! I was looking under the wrong name....
>
> Now, thank you, I'm looking in the right place so I see.....
>
> ruby --version
> ruby 1.8.7 (2008-06-20 patchlevel 22) [i686-linux]
> $ ruby -e 'def foo;p __method__;end;foo'
> :foo
>
> Are you're saying that this behaviour change in 1.9?

Doesn't look like so:

sandal:Desktop $ ruby -v
ruby 1.9.1 (2008-10-28 revision 19983) [i386-darwin9.4.0]
sandal:Desktop $ irb
>> __method__
=> :irb_binding
>> def foo
>>  __method__
>> end
=> nil
>> foo
=> :foo

Just keep in mind that Ruby 1.8.7 isn't a compatible Ruby 1.8 version.
 It's meant for um... I don't really know what, and if you want your
code to run on Ruby 1.8.6 (which is pretty important if you plan to
support 1.8 at all, IMO), it's not there:

sandal:prawn $ ruby -v
ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-darwin9.4.0]
sandal:prawn $ irb
>> __method__
NameError: undefined local variable or method `__method__' for
main:Object
  from (irb):1
  from :0
This topic is locked and can not be replied to.