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
Not to mention
irb(main):001:0> Integer :"42"
=> 15665
martin
> 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
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.