Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interger( a_symbol ) raises no exception

0 views
Skip to first unread message

Stephan Kämper

unread,
Nov 11, 2005, 1:48:57 AM11/11/05
to
Hi all,

yesterday at work I tried to program this: Read a simple (YAML) file
contaning key values pairs and create an object which has accessor
methods for each pair, the key name being the method name.

All went well until I realised that I'd have to treat integer values in
a slightly special way. No problem I thought, evaluate

Integer( current_value )

and if that doesn't raise an exception, go ahead...

To my surprise the Symbols dissappeared and there were ints instead.

irb(main):001:0> Integer :oops
=> 23417

Why doesn't that rains an exception?
I alwasy thought Symbols were closer to Strings than Integers (resp.
Fixnums), but I might have been wrong.

What's the reason for this behaviour?

I now that there's a unique int associated to each Symbol, but I still
think that a String like "42" IS more like an Integer, than
:a_symbol_like_this.

Happy rubying

Stephan

Martin DeMello

unread,
Nov 11, 2005, 2:08:09 AM11/11/05
to
Stephan Kämper <Stephan...@schleswig-holstein.de> wrote:
>
> I now that there's a unique int associated to each Symbol, but I still
> think that a String like "42" IS more like an Integer, than
> :a_symbol_like_this.

Not to mention

irb(main):001:0> Integer :"42"
=> 15665

martin

Eric Hodel

unread,
Nov 11, 2005, 4:04:45 AM11/11/05
to
On Nov 10, 2005, at 10:52 PM, Stephan Kämper wrote:

> irb(main):001:0> Integer :oops
> => 23417
>
> Why doesn't that rains an exception?
> I alwasy thought Symbols were closer to Strings than Integers
> (resp. Fixnums), but I might have been wrong.
>
> What's the reason for this behaviour?
>
> I now that there's a unique int associated to each Symbol, but I
> still think that a String like "42" IS more like an Integer,
> than :a_symbol_like_this.

Symbols were originally just numbers, so they have #to_int defined
for backwards compatibility.

--
Eric Hodel - drb...@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


Yukihiro Matsumoto

unread,
Nov 11, 2005, 9:13:57 AM11/11/05
to
Hi,

In message "Re: Interger( a_symbol ) raises no exception"


on Fri, 11 Nov 2005 18:04:45 +0900, Eric Hodel <drb...@segment7.net> writes:

|Symbols were originally just numbers, so they have #to_int defined
|for backwards compatibility.

Until 1.8. 1.9 symbols does not have to_int any longer.

matz.


0 new messages